dark, classic und bright theme korrekt eingefügt auf allen 3 seiten

This commit is contained in:
OliverT87 2025-06-21 13:14:33 +02:00
parent 53d3a39fa5
commit fa43a710ab
2 changed files with 25 additions and 10 deletions

View File

@ -30,14 +30,12 @@
HorizontalAlignment="Center"> HorizontalAlignment="Center">
<TextBlock Text="Author: Oliver Träger" <TextBlock Text="Author: Oliver Träger"
FontSize="20" FontSize="20"
Foreground="White"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Margin="0,0,0,10"/> Margin="0,0,0,10"/>
<TextBlock Text="Klasse: ITFS2" <TextBlock Text="Klasse: ITFS2"
FontSize="20" FontSize="20"
Foreground="White" HorizontalAlignment="Center"
HorizontalAlignment="Center" Margin="0,0,0,10"/>
Margin="0,0,0,10"/>
<TextBlock Text="SS2025" <TextBlock Text="SS2025"
FontSize="20" FontSize="20"
Foreground="White" Foreground="White"

View File

@ -1,9 +1,12 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.VisualTree;
using Project_Periodensystem.Model; using Project_Periodensystem.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using static Project_Periodensystem.Model.AppTheme;
namespace Project_Periodensystem.View namespace Project_Periodensystem.View
{ {
@ -11,11 +14,12 @@ namespace Project_Periodensystem.View
{ {
private ContentControl? mainContent; private ContentControl? mainContent;
public static AppTheme CurrentTheme { get; set; } = AppTheme.Dark; public static AppTheme CurrentTheme { get; set; } = AppTheme.Dark;
public static Dictionary<AppTheme, string> ThemeColors { get; } = new()
public static Dictionary<AppTheme, (string Background, string Foreground)> ThemeColors { get; } = new()
{ {
{ AppTheme.Dark, "#5C5144" }, { AppTheme.Dark, ("#2F2F2F", "#FFFFFF") }, // Dunkles Anthrazit & Weiß
{ AppTheme.Light, "#E8DFD8" }, { AppTheme.Light, ("#FFFFFF", "#000000") }, // Weiß & Schwarz
{ AppTheme.Classic, "#7B8B6F" } { AppTheme.Classic, ("#E8E8E8", "#000000") } // Stylisches Grau & Schwarz
}; };
public MainWindow() public MainWindow()
@ -28,16 +32,19 @@ namespace Project_Periodensystem.View
public void ShowLandingPage() public void ShowLandingPage()
{ {
mainContent!.Content = new LandingPage(); mainContent!.Content = new LandingPage();
UpdateTheme(AppTheme.Dark);
} }
public void ShowPeriodicTable() public void ShowPeriodicTable()
{ {
mainContent!.Content = new PeriodicTablePage(); mainContent!.Content = new PeriodicTablePage();
UpdateTheme(AppTheme.Dark);
} }
public void ShowAboutPage() public void ShowAboutPage()
{ {
mainContent!.Content = new AboutPage(); mainContent!.Content = new AboutPage();
UpdateTheme(AppTheme.Dark);
} }
public void UpdateTheme(AppTheme theme) public void UpdateTheme(AppTheme theme)
@ -45,7 +52,17 @@ namespace Project_Periodensystem.View
CurrentTheme = theme; CurrentTheme = theme;
if (mainContent?.Content is UserControl control) if (mainContent?.Content is UserControl control)
{ {
control.Background = new SolidColorBrush(Color.Parse(ThemeColors[theme])); 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>())
{
if (textBlock.Parent is Button || textBlock.Parent.ToString().Contains("ElementTile"))
continue;
textBlock.Foreground = new SolidColorBrush(Color.Parse(foreground));
}
} }
} }
} }