implemented highlighting of the grid via button.
This commit is contained in:
parent
4485385255
commit
e4aa132c79
@ -19,7 +19,7 @@ namespace Project_Periodensystem.View
|
||||
InitializeComponent();
|
||||
mainContent = this.FindControl<ContentControl>("MainContent");
|
||||
|
||||
// Erstelle Navigation Service
|
||||
// Erstelle Navigation Service mit this (MainWindow)
|
||||
_navigationService = new NavigationService(this);
|
||||
|
||||
// Controller mit Navigation Service initialisieren (Dependency Injection)
|
||||
|
||||
@ -14,13 +14,13 @@ namespace Project_Periodensystem.View
|
||||
/// </summary>
|
||||
public class NavigationService : INavigationService
|
||||
{
|
||||
private readonly Window _mainWindow;
|
||||
private readonly MainWindow _mainWindow;
|
||||
private PeriodensystemController? _dataController;
|
||||
|
||||
/// <summary>
|
||||
/// Konstruktor
|
||||
/// </summary>
|
||||
public NavigationService(Window mainWindow)
|
||||
public NavigationService(MainWindow mainWindow)
|
||||
{
|
||||
_mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow));
|
||||
Logger.Log("NavigationService initialisiert - saubere Interface-Trennung");
|
||||
@ -50,8 +50,16 @@ namespace Project_Periodensystem.View
|
||||
var periodicTablePage = new PeriodicTablePage();
|
||||
periodicTablePage.SetController(_dataController);
|
||||
|
||||
_mainWindow.Content = periodicTablePage;
|
||||
Logger.Log("NavigationService: Navigation zum Periodensystem");
|
||||
var mainContent = _mainWindow.FindControl<ContentControl>("MainContent");
|
||||
if (mainContent != null)
|
||||
{
|
||||
mainContent.Content = periodicTablePage;
|
||||
Logger.Log("NavigationService: Navigation zum Periodensystem");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("MainContent Control nicht gefunden");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -75,8 +83,16 @@ namespace Project_Periodensystem.View
|
||||
var aboutPage = new AboutPage();
|
||||
aboutPage.SetController(_dataController);
|
||||
|
||||
_mainWindow.Content = aboutPage;
|
||||
Logger.Log("NavigationService: Navigation zu About");
|
||||
var mainContent = _mainWindow.FindControl<ContentControl>("MainContent");
|
||||
if (mainContent != null)
|
||||
{
|
||||
mainContent.Content = aboutPage;
|
||||
Logger.Log("NavigationService: Navigation zu About");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("MainContent Control nicht gefunden");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -100,8 +116,16 @@ namespace Project_Periodensystem.View
|
||||
var landingPage = new LandingPage();
|
||||
landingPage.SetController(_dataController);
|
||||
|
||||
_mainWindow.Content = landingPage;
|
||||
Logger.Log("NavigationService: Navigation zur Landing Page");
|
||||
var mainContent = _mainWindow.FindControl<ContentControl>("MainContent");
|
||||
if (mainContent != null)
|
||||
{
|
||||
mainContent.Content = landingPage;
|
||||
Logger.Log("NavigationService: Navigation zur Landing Page");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("MainContent Control nicht gefunden");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@ -43,6 +43,12 @@
|
||||
<Setter Property="Margin" Value="2"/>
|
||||
</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 -->
|
||||
<Style Selector="Button.ElementTile > StackPanel > TextBlock">
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
@ -86,6 +92,32 @@
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
</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.Resources>
|
||||
@ -100,47 +132,52 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Legend - ohne dunklen Hintergrund -->
|
||||
<!-- Legend - jetzt mit klickbaren Buttons -->
|
||||
<WrapPanel Grid.Row="0"
|
||||
Name="LegendPanel"
|
||||
HorizontalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
|
||||
<!-- Farben aus SeriesToColorConverter verwenden -->
|
||||
<Border Classes="LegendItem" Background="#6c3b01">
|
||||
<TextBlock Text="Alkalimetalle"/>
|
||||
</Border>
|
||||
<!-- Farben aus SeriesToColorConverter verwenden - jetzt als Buttons -->
|
||||
<Button Classes="LegendButton" Background="#6c3b01"
|
||||
Content="Alkalimetalle" Click="LegendButton_Click"
|
||||
Tag="Alkalimetall"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#846011">
|
||||
<TextBlock Text="Erdalkalimetalle"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#846011"
|
||||
Content="Erdalkalimetalle" Click="LegendButton_Click"
|
||||
Tag="Erdalkalimetall"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#402c17">
|
||||
<TextBlock Text="Lanthanoide"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#402c17"
|
||||
Content="Lanthanoide" Click="LegendButton_Click"
|
||||
Tag="Lanthanoid"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#732e4c">
|
||||
<TextBlock Text="Actinoide"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#732e4c"
|
||||
Content="Actinoide" Click="LegendButton_Click"
|
||||
Tag="Actinoid"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#711019">
|
||||
<TextBlock Text="Übergangsmetalle"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#711019"
|
||||
Content="Übergangsmetalle" Click="LegendButton_Click"
|
||||
Tag="Metall"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#555555">
|
||||
<TextBlock Text="Post-Übergang"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#555555"
|
||||
Content="Post-Übergang" Click="LegendButton_Click"
|
||||
Tag="Post-Übergangsmetall"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#015146">
|
||||
<TextBlock Text="Halbmetalle"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#015146"
|
||||
Content="Halbmetalle" Click="LegendButton_Click"
|
||||
Tag="Halbmetall"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#3e6418">
|
||||
<TextBlock Text="Nichtmetalle"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#3e6418"
|
||||
Content="Nichtmetalle" Click="LegendButton_Click"
|
||||
Tag="Nichtmetall"/>
|
||||
|
||||
<Border Classes="LegendItem" Background="#3a2151">
|
||||
<TextBlock Text="Edelgase"/>
|
||||
</Border>
|
||||
<Button Classes="LegendButton" Background="#3a2151"
|
||||
Content="Edelgase" Click="LegendButton_Click"
|
||||
Tag="Edelgas"/>
|
||||
|
||||
<Button Classes="LegendButton" Background="#846011"
|
||||
Content="Halogene" Click="LegendButton_Click"
|
||||
Tag="Halogen"/>
|
||||
|
||||
</WrapPanel>
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
@ -19,6 +20,11 @@ namespace Project_Periodensystem.View
|
||||
{
|
||||
private readonly Grid? periodicGrid;
|
||||
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>
|
||||
/// Konstruktor - initialisiert UI (Controller wird per SetController gesetzt)
|
||||
@ -90,6 +96,9 @@ namespace Project_Periodensystem.View
|
||||
}
|
||||
|
||||
Logger.Log($"{successCount} von {elements.Count} Elementen erfolgreich geladen");
|
||||
|
||||
// Legend-Buttons sammeln für Highlighting-Funktionalität
|
||||
CollectLegendButtons();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -113,6 +122,10 @@ namespace Project_Periodensystem.View
|
||||
var button = new Button { Classes = { "ElementTile" } };
|
||||
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
|
||||
var backgroundColor = new SeriesToColorConverter()
|
||||
.Convert(element.Series, typeof(Brush), null, CultureInfo.InvariantCulture) as Brush;
|
||||
@ -255,5 +268,158 @@ namespace Project_Periodensystem.View
|
||||
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.
Loading…
Reference in New Issue
Block a user