From e53d02d3ba1b4766e482612d603111c6178a7258 Mon Sep 17 00:00:00 2001 From: Mommel Date: Sat, 9 May 2026 00:34:24 +0200 Subject: [PATCH] feat: implement dark and light mode --- App.xaml | 6 +- App.xaml.cs | 45 ++++++++++ MainWindow.xaml | 173 ++++++++++++++++++++++++++++-------- MainWindow.xaml.cs | 183 ++++++++++++++++++++++++++++----------- SettingsManager.cs | 68 +++++++++++++++ SettingsWindow.xaml | 17 ++++ SettingsWindow.xaml.cs | 48 ++++++++++ Themes/DarkMode.xaml | 11 +++ Themes/GlobalStyles.xaml | 74 ++++++++++++++++ Themes/LightMode.xaml | 11 +++ UnifiedExplorer.csproj | 4 +- 11 files changed, 554 insertions(+), 86 deletions(-) create mode 100644 SettingsManager.cs create mode 100644 SettingsWindow.xaml create mode 100644 SettingsWindow.xaml.cs create mode 100644 Themes/DarkMode.xaml create mode 100644 Themes/GlobalStyles.xaml create mode 100644 Themes/LightMode.xaml diff --git a/App.xaml b/App.xaml index 506bf19..75958f9 100644 --- a/App.xaml +++ b/App.xaml @@ -3,6 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> - + + + + + diff --git a/App.xaml.cs b/App.xaml.cs index 1c3bc48..2381b0b 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,8 +1,53 @@ +using System; using System.Windows; +using Microsoft.Win32; namespace UnifiedExplorer { public partial class App : Application { + public static AppSettings Settings { get; set; } = new AppSettings(); + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + Settings = SettingsManager.LoadSettings(); + ApplyTheme(Settings.Theme); + + SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged; + } + + private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) + { + if (e.Category == UserPreferenceCategory.General && Settings.Theme == ThemeMode.System) + { + ApplyTheme(ThemeMode.System); + } + } + + public static void ApplyTheme(ThemeMode mode) + { + Settings.Theme = mode; + SettingsManager.SaveSettings(Settings); + + bool isLight = true; + if (mode == ThemeMode.Dark) + { + isLight = false; + } + else if (mode == ThemeMode.System) + { + isLight = SettingsManager.IsSystemThemeLight(); + } + + var dict = new ResourceDictionary(); + dict.Source = isLight + ? new Uri("Themes/LightMode.xaml", UriKind.Relative) + : new Uri("Themes/DarkMode.xaml", UriKind.Relative); + + Current.Resources.MergedDictionaries.Clear(); + Current.Resources.MergedDictionaries.Add(dict); + } } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 52fdfec..555984a 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -3,7 +3,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="root" Title="Unified Explorer" Height="700" Width="1200" Loaded="Window_Loaded" - Icon="pack://application:,,,/assets/app.ico"> + Icon="pack://application:,,,/assets/app.ico" + Background="{DynamicResource BackgroundColor}" + Foreground="{DynamicResource TextColor}"> Segoe Fluent Icons, Segoe MDL2 Assets @@ -26,19 +28,34 @@ - - - + + + @@ -49,14 +66,14 @@ -