Projekt_SS25/Project_Periodensystem.View/MainWindow.axaml.cs
2025-06-21 13:16:44 +02:00

75 lines
2.4 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.VisualTree;
using Project_Periodensystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using static Project_Periodensystem.Model.AppTheme;
namespace Project_Periodensystem.View
{
public partial class MainWindow : Window
{
private ContentControl? mainContent;
public static AppTheme CurrentTheme { get; set; } = AppTheme.Dark;
public static Dictionary<AppTheme, (string Background, string Foreground)> ThemeColors { get; } = new()
{
{ AppTheme.Dark, ("#2F2F2F", "#FFFFFF") }, // Dunkles Anthrazit & Weiß
{ AppTheme.Light, ("#FFFFFF", "#000000") }, // Weiß & Schwarz
{ AppTheme.Classic, ("#E8E8E8", "#000000") } // Stylisches Grau & Schwarz
};
public MainWindow()
{
InitializeComponent();
mainContent = this.FindControl<ContentControl>("MainContent");
ShowLandingPage();
}
public void ShowLandingPage()
{
mainContent!.Content = new LandingPage();
UpdateTheme(AppTheme.Dark);
}
public void ShowPeriodicTable()
{
mainContent!.Content = new PeriodicTablePage();
UpdateTheme(AppTheme.Dark);
}
public void ShowAboutPage()
{
mainContent!.Content = new AboutPage();
UpdateTheme(AppTheme.Dark);
}
public void UpdateTheme(AppTheme theme)
{
CurrentTheme = theme;
if (mainContent?.Content is UserControl control)
{
var (background, foreground) = ThemeColors[theme];
control.Background = new SolidColorBrush(Color.Parse(background));
// Update text colors for all direct TextBlocks
foreach (var textBlock in control.GetVisualDescendants().OfType<TextBlock>())
{
var parent = textBlock.Parent;
if (parent == null ||
parent is Button ||
parent?.GetType().ToString().Contains("ElementTile") == true)
{
continue;
}
textBlock.Foreground = new SolidColorBrush(Color.Parse(foreground));
}
}
}
}
}