diff --git a/Project_Periodensystem.Model/ElementModel.cs b/Project_Periodensystem.Model/ElementModel.cs new file mode 100644 index 0000000..bb82d07 --- /dev/null +++ b/Project_Periodensystem.Model/ElementModel.cs @@ -0,0 +1,25 @@ +namespace Project_Periodensystem.Model +{ + public class ElementModel + { + public string Symbol { get; set; } = ""; + public int Number { get; set; } + public int Row { get; set; } + public int Column { get; set; } + public ElementSeries Series { get; set; } + } + + public enum ElementSeries + { + Alkali, + AlkalineEarth, + Transition, + PostTransition, + Metalloid, + Nonmetal, + Halogen, + NobleGas, + Lanthanide, + Actinide + } +} \ No newline at end of file diff --git a/Project_Periodensystem.View/AboutPage.axaml b/Project_Periodensystem.View/AboutPage.axaml index f20699c..5dfe90a 100644 --- a/Project_Periodensystem.View/AboutPage.axaml +++ b/Project_Periodensystem.View/AboutPage.axaml @@ -2,13 +2,18 @@ + x:Class="Project_Periodensystem.View.AboutPage"> + @@ -29,47 +39,32 @@ VerticalAlignment="Center" HorizontalAlignment="Center"> + FontSize="24" + Margin="0,0,0,20"/> - + FontSize="24" + Margin="0,0,0,20"/> - - + - - - - diff --git a/Project_Periodensystem.View/AboutPage.axaml.cs b/Project_Periodensystem.View/AboutPage.axaml.cs index 0de901c..fee854f 100644 --- a/Project_Periodensystem.View/AboutPage.axaml.cs +++ b/Project_Periodensystem.View/AboutPage.axaml.cs @@ -1,4 +1,5 @@ using System; +using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; @@ -14,6 +15,16 @@ namespace Project_Periodensystem.View InitializeComponent(); } + protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) + { + base.OnAttachedToVisualTree(e); + + if (this.GetVisualRoot() is MainWindow mainWindow) + { + mainWindow.UpdateTheme(MainWindow.CurrentTheme); + } + } + private void InitializeComponent() { AvaloniaXamlLoader.Load(this); @@ -21,24 +32,20 @@ namespace Project_Periodensystem.View private void BackButton_Click(object? sender, RoutedEventArgs e) { - if (this.Parent is ContentControl content && content.Parent is MainWindow mainWindow) + if (MainWindow.Instance != null) { - mainWindow.ShowLandingPage(); + MainWindow.Instance.ShowLandingPage(); } } private void ThemeButton_Click(object? sender, RoutedEventArgs e) { - var nextTheme = MainWindow.CurrentTheme switch + var themes = Enum.GetValues(); + MainWindow.CurrentTheme = themes[(Array.IndexOf(themes, MainWindow.CurrentTheme) + 1) % themes.Length]; + + if (MainWindow.Instance != null) { - AppTheme.Dark => AppTheme.Light, - AppTheme.Light => AppTheme.Classic, - _ => AppTheme.Dark - }; - - if (this.Parent is ContentControl content && content.Parent is MainWindow mainWindow) - { - mainWindow.UpdateTheme(nextTheme); + MainWindow.Instance.UpdateTheme(MainWindow.CurrentTheme); } } } diff --git a/Project_Periodensystem.View/LandingPage.axaml b/Project_Periodensystem.View/LandingPage.axaml index 34374fa..695ac68 100644 --- a/Project_Periodensystem.View/LandingPage.axaml +++ b/Project_Periodensystem.View/LandingPage.axaml @@ -1,11 +1,15 @@ + x:Class="Project_Periodensystem.View.LandingPage"> + + + + + + + + + + + + + + + + + + + + + @@ -110,4 +164,5 @@ - \ No newline at end of file + + diff --git a/Project_Periodensystem.View/PeriodicTablePage.axaml.cs b/Project_Periodensystem.View/PeriodicTablePage.axaml.cs index 086d415..08ba328 100644 --- a/Project_Periodensystem.View/PeriodicTablePage.axaml.cs +++ b/Project_Periodensystem.View/PeriodicTablePage.axaml.cs @@ -3,7 +3,7 @@ using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Media; -using Project_Periodensystem.Model; +using Project_Periodensystem.Model; // ElementModel should be here using Project_Periodensystem.Persistence; using Project_Periodensystem.View.Converters; using System; @@ -48,51 +48,33 @@ namespace Project_Periodensystem.View return; } - var converter = new SeriesToColorConverter(); + // Debug: Alle Elemente ausgeben + Logger.Log($"Anzahl Elemente: {PeriodicTableData.Elements.Count()}"); + var firstFew = PeriodicTableData.Elements.Take(5); + foreach (var el in firstFew) + { + Logger.Log($"Element: {el.Symbol} - Row: {el.Row}, Column: {el.Column}"); + } + + // Speziell nach H und He suchen + var hydrogen = PeriodicTableData.Elements.FirstOrDefault(e => e.Symbol == "H"); + var helium = PeriodicTableData.Elements.FirstOrDefault(e => e.Symbol == "He"); + + if (hydrogen != null) + Logger.Log($"Wasserstoff gefunden: Row {hydrogen.Row}, Column {hydrogen.Column}"); + else + Logger.Log("Wasserstoff NICHT gefunden!"); + + if (helium != null) + Logger.Log($"Helium gefunden: Row {helium.Row}, Column {helium.Column}"); + else + Logger.Log("Helium NICHT gefunden!"); + // Elemente hinzufügen foreach (var element in PeriodicTableData.Elements) { Logger.Log($"Füge Element hinzu: {element.Symbol} ({element.Row},{element.Column})"); - - var border = new Border - { - Width = 58, - Height = 58, - Margin = new Thickness(1), - CornerRadius = new CornerRadius(4), - BorderThickness = new Thickness(1), - BorderBrush = new SolidColorBrush(Colors.Gray), - Background = converter.Convert(element.Series, typeof(IBrush), null!, CultureInfo.CurrentCulture) as IBrush // Hier wird die Farbe gesetzt - }; - - var stackPanel = new StackPanel(); - - // Symbol - stackPanel.Children.Add(new TextBlock - { - Text = element.Symbol, - FontSize = 20, - Foreground = new SolidColorBrush(Colors.White), - HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center - }); - - // Atomic Number - stackPanel.Children.Add(new TextBlock - { - Text = element.AtomicNumber.ToString(), - FontSize = 12, - Foreground = new SolidColorBrush(Colors.White), - HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center - }); - - border.Child = stackPanel; - - // Position setzen - Grid.SetRow(border, Math.Max(0, element.Row - 1)); - Grid.SetColumn(border, Math.Max(0, element.Column - 1)); - - periodicGrid.Children.Add(border); - Logger.Log($"Element {element.Symbol} wurde hinzugefügt"); + CreateElementButton(element); } Logger.Log("PeriodicTable wurde initialisiert"); @@ -104,6 +86,54 @@ namespace Project_Periodensystem.View } } + private void CreateElementButton(Element element) + { + var button = new Button { Classes = { "ElementTile" } }; + var panel = new StackPanel(); + + // Set background color based on element series + var backgroundColor = new SeriesToColorConverter().Convert(element.Series, typeof(Brush), null, CultureInfo.InvariantCulture) as Brush; + if (backgroundColor != null) + { + button.Background = backgroundColor; + } + + var symbolText = new TextBlock + { + Text = element.Symbol, + Classes = { "Symbol" }, + Foreground = new SolidColorBrush(Colors.White), + HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center + }; + + var numberText = new TextBlock + { + Text = element.AtomicNumber.ToString(), + Classes = { "Number" }, + Foreground = new SolidColorBrush(Colors.White), + HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center + }; + + panel.Children.Add(numberText); // Number on top + panel.Children.Add(symbolText); // Symbol below + button.Content = panel; + + // FIX: Korrekte Grid-Positionierung ohne Math.Max für Spalten! + int gridRow = element.Row; // Row direkt verwenden (0-basiert) + int gridColumn = element.Column; // Column direkt verwenden (0-basiert) + + Logger.Log($"Element {element.Symbol}: Original({element.Row},{element.Column}) -> Grid({gridRow},{gridColumn})"); + + Grid.SetRow(button, gridRow); + Grid.SetColumn(button, gridColumn); + + if (periodicGrid != null) + { + periodicGrid.Children.Add(button); + Logger.Log($"Element {element.Symbol} wurde zum Grid hinzugefügt an Position ({gridRow},{gridColumn})"); + } + } + private void ThemeButton_Click(object? sender, RoutedEventArgs e) { var nextTheme = MainWindow.CurrentTheme switch