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 @@ -