diff --git a/Project_Periodensystem.View/PeriodicTablePage.axaml b/Project_Periodensystem.View/PeriodicTablePage.axaml index 49038f8..06754af 100644 --- a/Project_Periodensystem.View/PeriodicTablePage.axaml +++ b/Project_Periodensystem.View/PeriodicTablePage.axaml @@ -1,9 +1,15 @@ - - + xmlns:conv="clr-namespace:Project_Periodensystem.View.Converters" + x:Class="Project_Periodensystem.View.PeriodicTablePage" + Background="Beige"> + + + + + + @@ -14,54 +20,59 @@ + Margin="0,0,0,20"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Project_Periodensystem.View/PeriodicTablePage.axaml.cs b/Project_Periodensystem.View/PeriodicTablePage.axaml.cs index e23a2b6..4a54cb0 100644 --- a/Project_Periodensystem.View/PeriodicTablePage.axaml.cs +++ b/Project_Periodensystem.View/PeriodicTablePage.axaml.cs @@ -1,11 +1,15 @@ using System; +using System.Globalization; +using System.Linq; +using Avalonia; using Avalonia.Controls; +using Avalonia.Data.Converters; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Media; -using Avalonia; using Avalonia.VisualTree; using Project_Periodensystem.Persistence; +using Project_Periodensystem.View.Converters; namespace Project_Periodensystem.View { @@ -14,38 +18,33 @@ namespace Project_Periodensystem.View { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { - // Example: Map series string to color if (value == null) return new SolidColorBrush(Colors.Gray); - switch (value.ToString()) + + return value.ToString() switch { - case "Alkali Metal": - return new SolidColorBrush(Colors.OrangeRed); - case "Alkaline Earth Metal": - return new SolidColorBrush(Colors.Gold); - case "Transition Metal": - return new SolidColorBrush(Colors.LightBlue); - case "Metalloid": - return new SolidColorBrush(Colors.LightGreen); - case "Nonmetal": - return new SolidColorBrush(Colors.LightGray); - case "Halogen": - return new SolidColorBrush(Colors.Violet); - case "Noble Gas": - return new SolidColorBrush(Colors.Cyan); - default: - return new SolidColorBrush(Colors.Gray); - } + "Nichtmetall" => new SolidColorBrush(Color.Parse("#3e6418")), + "Metall" => new SolidColorBrush(Color.Parse("#711019")), + "Post-Übergangsmetall" => new SolidColorBrush(Color.Parse("#555555")), + "Halbmetall" => new SolidColorBrush(Color.Parse("#015146")), + "Edelgas" => new SolidColorBrush(Color.Parse("#3a2151")), + "Halogen" => new SolidColorBrush(Color.Parse("#846011")), + "Alkalimetall" => new SolidColorBrush(Color.Parse("#6c3b01")), + "Erdalkalimetall" => new SolidColorBrush(Color.Parse("#846011")), + "Lanthanoid" => new SolidColorBrush(Color.Parse("#402c17")), + "Actinoid" => new SolidColorBrush(Color.Parse("#732e4c")), + _ => new SolidColorBrush(Color.Parse("#222222")) + }; } } public partial class PeriodicTablePage : UserControl { - private readonly Grid periodicGrid; + private readonly Grid? periodicGrid; public PeriodicTablePage() { InitializeComponent(); - periodicGrid = this.Find("PeriodicGrid") ?? throw new Exception("PeriodicGrid not found"); + periodicGrid = this.Find("PeriodicGrid"); InitializePeriodicTable(); } @@ -59,8 +58,27 @@ namespace Project_Periodensystem.View try { Logger.Log("Initialisiere PeriodicTable..."); + + // Prüfen ob das Grid gefunden wurde + if (periodicGrid == null) + { + Logger.Log("FEHLER: PeriodicGrid nicht gefunden!"); + return; + } + + // Prüfen ob Elemente vorhanden sind + if (PeriodicTableData.Elements == null || !PeriodicTableData.Elements.Any()) + { + Logger.Log("FEHLER: Keine Elemente in PeriodicTableData!"); + return; + } + + var converter = new SeriesToColorConverter(); + // 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, @@ -68,7 +86,8 @@ namespace Project_Periodensystem.View Margin = new Thickness(1), CornerRadius = new CornerRadius(4), BorderThickness = new Thickness(1), - BorderBrush = new SolidColorBrush(Colors.Gray) + 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(); @@ -93,31 +112,20 @@ namespace Project_Periodensystem.View border.Child = stackPanel; - // Set background color based on element series - var converter = new SeriesToColorConverter(); - border.Background = converter.Convert(element.Series, typeof(IBrush), null!, System.Globalization.CultureInfo.CurrentCulture) as IBrush; - - // Position the element - adjust for 0-based indexing + // 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"); } + Logger.Log("PeriodicTable wurde initialisiert"); } catch (Exception ex) { - var mainWindow = this.FindAncestorOfType(); - if (mainWindow != null) - { - Logger.Log("MainWindow gefunden, navigiere zu About..."); - mainWindow.ShowAbout(); - } - else - { - Logger.Log("FEHLER: MainWindow nicht gefunden!"); - } - Logger.Log($"FEHLER im PeriodicTable-Initialisierer: {ex.Message}"); + Logger.Log($"FEHLER beim Initialisieren des PeriodicTable: {ex.Message}"); + Logger.Log($"StackTrace: {ex.StackTrace}"); } }