implemented highlighting of the grid via button.

This commit is contained in:
OliverT87 2025-06-27 09:25:16 +02:00
parent 4485385255
commit e4aa132c79
5 changed files with 265 additions and 38 deletions

View File

@ -19,7 +19,7 @@ namespace Project_Periodensystem.View
InitializeComponent(); InitializeComponent();
mainContent = this.FindControl<ContentControl>("MainContent"); mainContent = this.FindControl<ContentControl>("MainContent");
// Erstelle Navigation Service // Erstelle Navigation Service mit this (MainWindow)
_navigationService = new NavigationService(this); _navigationService = new NavigationService(this);
// Controller mit Navigation Service initialisieren (Dependency Injection) // Controller mit Navigation Service initialisieren (Dependency Injection)

View File

@ -14,13 +14,13 @@ namespace Project_Periodensystem.View
/// </summary> /// </summary>
public class NavigationService : INavigationService public class NavigationService : INavigationService
{ {
private readonly Window _mainWindow; private readonly MainWindow _mainWindow;
private PeriodensystemController? _dataController; private PeriodensystemController? _dataController;
/// <summary> /// <summary>
/// Konstruktor /// Konstruktor
/// </summary> /// </summary>
public NavigationService(Window mainWindow) public NavigationService(MainWindow mainWindow)
{ {
_mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow)); _mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow));
Logger.Log("NavigationService initialisiert - saubere Interface-Trennung"); Logger.Log("NavigationService initialisiert - saubere Interface-Trennung");
@ -50,9 +50,17 @@ namespace Project_Periodensystem.View
var periodicTablePage = new PeriodicTablePage(); var periodicTablePage = new PeriodicTablePage();
periodicTablePage.SetController(_dataController); periodicTablePage.SetController(_dataController);
_mainWindow.Content = periodicTablePage; var mainContent = _mainWindow.FindControl<ContentControl>("MainContent");
if (mainContent != null)
{
mainContent.Content = periodicTablePage;
Logger.Log("NavigationService: Navigation zum Periodensystem"); Logger.Log("NavigationService: Navigation zum Periodensystem");
} }
else
{
Logger.LogError("MainContent Control nicht gefunden");
}
}
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogException(ex, "NavigateToPeriodicTable"); Logger.LogException(ex, "NavigateToPeriodicTable");
@ -75,9 +83,17 @@ namespace Project_Periodensystem.View
var aboutPage = new AboutPage(); var aboutPage = new AboutPage();
aboutPage.SetController(_dataController); aboutPage.SetController(_dataController);
_mainWindow.Content = aboutPage; var mainContent = _mainWindow.FindControl<ContentControl>("MainContent");
if (mainContent != null)
{
mainContent.Content = aboutPage;
Logger.Log("NavigationService: Navigation zu About"); Logger.Log("NavigationService: Navigation zu About");
} }
else
{
Logger.LogError("MainContent Control nicht gefunden");
}
}
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogException(ex, "NavigateToAbout"); Logger.LogException(ex, "NavigateToAbout");
@ -100,9 +116,17 @@ namespace Project_Periodensystem.View
var landingPage = new LandingPage(); var landingPage = new LandingPage();
landingPage.SetController(_dataController); landingPage.SetController(_dataController);
_mainWindow.Content = landingPage; var mainContent = _mainWindow.FindControl<ContentControl>("MainContent");
if (mainContent != null)
{
mainContent.Content = landingPage;
Logger.Log("NavigationService: Navigation zur Landing Page"); Logger.Log("NavigationService: Navigation zur Landing Page");
} }
else
{
Logger.LogError("MainContent Control nicht gefunden");
}
}
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogException(ex, "NavigateToLanding"); Logger.LogException(ex, "NavigateToLanding");

View File

@ -43,6 +43,12 @@
<Setter Property="Margin" Value="2"/> <Setter Property="Margin" Value="2"/>
</Style> </Style>
<!-- Highlighted element tile style -->
<Style Selector="Button.ElementTile.Highlighted">
<Setter Property="BorderBrush" Value="Yellow"/>
<Setter Property="BorderThickness" Value="4"/>
</Style>
<!-- Specific styles for element tile content --> <!-- Specific styles for element tile content -->
<Style Selector="Button.ElementTile > StackPanel > TextBlock"> <Style Selector="Button.ElementTile > StackPanel > TextBlock">
<Setter Property="Foreground" Value="White"/> <Setter Property="Foreground" Value="White"/>
@ -86,6 +92,32 @@
<Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/>
</Style> </Style>
<!-- Legend Button styles for clickable legend items -->
<Style Selector="Button.LegendButton">
<Setter Property="Width" Value="120"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
<!-- Highlighted legend button style -->
<Style Selector="Button.LegendButton.Highlighted">
<Setter Property="BorderBrush" Value="Yellow"/>
<Setter Property="BorderThickness" Value="3"/>
</Style>
<!-- Legend button hover effect -->
<Style Selector="Button.LegendButton:pointerover">
<Setter Property="Opacity" Value="0.8"/>
</Style>
</UserControl.Styles> </UserControl.Styles>
<UserControl.Resources> <UserControl.Resources>
@ -100,47 +132,52 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- Legend - ohne dunklen Hintergrund --> <!-- Legend - jetzt mit klickbaren Buttons -->
<WrapPanel Grid.Row="0" <WrapPanel Grid.Row="0"
Name="LegendPanel"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Orientation="Horizontal"> Orientation="Horizontal">
<!-- Farben aus SeriesToColorConverter verwenden --> <!-- Farben aus SeriesToColorConverter verwenden - jetzt als Buttons -->
<Border Classes="LegendItem" Background="#6c3b01"> <Button Classes="LegendButton" Background="#6c3b01"
<TextBlock Text="Alkalimetalle"/> Content="Alkalimetalle" Click="LegendButton_Click"
</Border> Tag="Alkalimetall"/>
<Border Classes="LegendItem" Background="#846011"> <Button Classes="LegendButton" Background="#846011"
<TextBlock Text="Erdalkalimetalle"/> Content="Erdalkalimetalle" Click="LegendButton_Click"
</Border> Tag="Erdalkalimetall"/>
<Border Classes="LegendItem" Background="#402c17"> <Button Classes="LegendButton" Background="#402c17"
<TextBlock Text="Lanthanoide"/> Content="Lanthanoide" Click="LegendButton_Click"
</Border> Tag="Lanthanoid"/>
<Border Classes="LegendItem" Background="#732e4c"> <Button Classes="LegendButton" Background="#732e4c"
<TextBlock Text="Actinoide"/> Content="Actinoide" Click="LegendButton_Click"
</Border> Tag="Actinoid"/>
<Border Classes="LegendItem" Background="#711019"> <Button Classes="LegendButton" Background="#711019"
<TextBlock Text="Übergangsmetalle"/> Content="Übergangsmetalle" Click="LegendButton_Click"
</Border> Tag="Metall"/>
<Border Classes="LegendItem" Background="#555555"> <Button Classes="LegendButton" Background="#555555"
<TextBlock Text="Post-Übergang"/> Content="Post-Übergang" Click="LegendButton_Click"
</Border> Tag="Post-Übergangsmetall"/>
<Border Classes="LegendItem" Background="#015146"> <Button Classes="LegendButton" Background="#015146"
<TextBlock Text="Halbmetalle"/> Content="Halbmetalle" Click="LegendButton_Click"
</Border> Tag="Halbmetall"/>
<Border Classes="LegendItem" Background="#3e6418"> <Button Classes="LegendButton" Background="#3e6418"
<TextBlock Text="Nichtmetalle"/> Content="Nichtmetalle" Click="LegendButton_Click"
</Border> Tag="Nichtmetall"/>
<Border Classes="LegendItem" Background="#3a2151"> <Button Classes="LegendButton" Background="#3a2151"
<TextBlock Text="Edelgase"/> Content="Edelgase" Click="LegendButton_Click"
</Border> Tag="Edelgas"/>
<Button Classes="LegendButton" Background="#846011"
Content="Halogene" Click="LegendButton_Click"
Tag="Halogen"/>
</WrapPanel> </WrapPanel>

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Avalonia; using Avalonia;
@ -20,6 +21,11 @@ namespace Project_Periodensystem.View
private readonly Grid? periodicGrid; private readonly Grid? periodicGrid;
private PeriodensystemController? _controller; private PeriodensystemController? _controller;
// Für Highlighting-Funktionalität
private string? _currentHighlightedSeries;
private readonly List<Button> _elementButtons = new List<Button>();
private readonly List<Button> _legendButtons = new List<Button>();
/// <summary> /// <summary>
/// Konstruktor - initialisiert UI (Controller wird per SetController gesetzt) /// Konstruktor - initialisiert UI (Controller wird per SetController gesetzt)
/// </summary> /// </summary>
@ -90,6 +96,9 @@ namespace Project_Periodensystem.View
} }
Logger.Log($"{successCount} von {elements.Count} Elementen erfolgreich geladen"); Logger.Log($"{successCount} von {elements.Count} Elementen erfolgreich geladen");
// Legend-Buttons sammeln für Highlighting-Funktionalität
CollectLegendButtons();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -113,6 +122,10 @@ namespace Project_Periodensystem.View
var button = new Button { Classes = { "ElementTile" } }; var button = new Button { Classes = { "ElementTile" } };
var panel = new StackPanel(); var panel = new StackPanel();
// Button-Referenz für Highlighting speichern
button.Tag = element; // Element-Daten im Tag speichern
_elementButtons.Add(button);
// Hintergrundfarbe über Converter setzen // Hintergrundfarbe über Converter setzen
var backgroundColor = new SeriesToColorConverter() var backgroundColor = new SeriesToColorConverter()
.Convert(element.Series, typeof(Brush), null, CultureInfo.InvariantCulture) as Brush; .Convert(element.Series, typeof(Brush), null, CultureInfo.InvariantCulture) as Brush;
@ -255,5 +268,158 @@ namespace Project_Periodensystem.View
Logger.LogException(ex, "ExportButton_Click"); Logger.LogException(ex, "ExportButton_Click");
} }
} }
/// <summary>
/// Event-Handler für Legende-Buttons - Highlighting-Funktionalität
/// </summary>
private void LegendButton_Click(object? sender, RoutedEventArgs e)
{
try
{
if (sender is not Button legendButton || legendButton.Tag?.ToString() is not string series)
{
Logger.LogError("LegendButton_Click: Ungültiger Button oder Tag");
return;
}
// Prüfen ob diese Serie bereits highlighted ist
if (_currentHighlightedSeries == series)
{
// Highlighting entfernen
ClearHighlighting();
Logger.Log($"Highlighting für {series} entfernt");
}
else
{
// Neue Serie highlighten
HighlightSeries(series);
Logger.Log($"Serie {series} wird highlighted");
}
}
catch (Exception ex)
{
Logger.LogException(ex, "LegendButton_Click");
}
}
/// <summary>
/// Hebt eine bestimmte Elementserie hervor
/// </summary>
private void HighlightSeries(string series)
{
try
{
// Zuerst alle Highlights entfernen
ClearHighlighting();
// Neue Serie als aktuell highlighted setzen
_currentHighlightedSeries = series;
// Element-Buttons highlighten, die zur Serie gehören
foreach (var button in _elementButtons)
{
if (button.Tag is Element element && element.Series == series)
{
button.Classes.Add("Highlighted");
}
}
// Legend-Button highlighten
var legendButton = GetLegendButtonForSeries(series);
if (legendButton != null)
{
legendButton.Classes.Add("Highlighted");
}
Logger.Log($"Highlighting für Serie '{series}' angewendet");
}
catch (Exception ex)
{
Logger.LogException(ex, "HighlightSeries");
}
}
/// <summary>
/// Entfernt alle Highlighting-Effekte
/// </summary>
private void ClearHighlighting()
{
try
{
_currentHighlightedSeries = null;
// Highlighting von allen Element-Buttons entfernen
foreach (var button in _elementButtons)
{
button.Classes.Remove("Highlighted");
}
// Highlighting von allen Legend-Buttons entfernen
foreach (var button in _legendButtons)
{
button.Classes.Remove("Highlighted");
}
Logger.Log("Alle Highlighting-Effekte entfernt");
}
catch (Exception ex)
{
Logger.LogException(ex, "ClearHighlighting");
}
}
/// <summary>
/// Findet den Legend-Button für eine bestimmte Serie
/// </summary>
private Button? GetLegendButtonForSeries(string series)
{
try
{
// Durchsuche alle Legend-Buttons
foreach (var button in _legendButtons)
{
if (button.Tag?.ToString() == series)
{
return button;
}
}
return null;
}
catch (Exception ex)
{
Logger.LogException(ex, "GetLegendButtonForSeries");
return null;
}
}
/// <summary>
/// Sammelt alle Legend-Button-Referenzen nach dem Laden der UI
/// </summary>
private void CollectLegendButtons()
{
try
{
_legendButtons.Clear();
// Finde alle Buttons mit der Klasse "LegendButton"
var legendPanel = this.FindControl<WrapPanel>("LegendPanel");
if (legendPanel != null)
{
foreach (var child in legendPanel.Children)
{
if (child is Button button && button.Classes.Contains("LegendButton"))
{
_legendButtons.Add(button);
}
}
}
Logger.Log($"{_legendButtons.Count} Legend-Buttons gefunden");
}
catch (Exception ex)
{
Logger.LogException(ex, "CollectLegendButtons");
}
}
} }
} }

Binary file not shown.