From 10adc77f9eed6844a199dedae617a49e4cb9f6da Mon Sep 17 00:00:00 2001 From: genteure Date: Sat, 16 Apr 2022 01:54:43 +0800 Subject: [PATCH] WPF: Add light/dark theme swtich --- BililiveRecorder.WPF/Pages/RootPage.xaml | 43 +++++++++++-------- BililiveRecorder.WPF/Pages/RootPage.xaml.cs | 17 ++++++++ .../Resources/IconResources.xaml | 3 ++ 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/BililiveRecorder.WPF/Pages/RootPage.xaml b/BililiveRecorder.WPF/Pages/RootPage.xaml index 53c3c37..8e3b3ee 100644 --- a/BililiveRecorder.WPF/Pages/RootPage.xaml +++ b/BililiveRecorder.WPF/Pages/RootPage.xaml @@ -55,24 +55,33 @@ IsPaneOpen="False" OpenPaneLength="200" SelectionChanged="NavigationView_SelectionChanged"> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + diff --git a/BililiveRecorder.WPF/Pages/RootPage.xaml.cs b/BililiveRecorder.WPF/Pages/RootPage.xaml.cs index d0a5158..ab35fd9 100644 --- a/BililiveRecorder.WPF/Pages/RootPage.xaml.cs +++ b/BililiveRecorder.WPF/Pages/RootPage.xaml.cs @@ -13,6 +13,7 @@ using BililiveRecorder.DependencyInjection; using BililiveRecorder.WPF.Controls; using BililiveRecorder.WPF.Models; using Microsoft.Extensions.DependencyInjection; +using ModernWpf; using ModernWpf.Controls; using ModernWpf.Media.Animation; using Serilog; @@ -338,5 +339,21 @@ You can uninstall me in system settings.", "安装成功 Installed", MessageBoxB { } } + + private void SwitchLightDarkTheme_Click(object sender, RoutedEventArgs e) + { + if (this.Dispatcher.CheckAccess()) + changeTheme(); + else + _ = this.Dispatcher.BeginInvoke(changeTheme); + + static void changeTheme() + { + ThemeManager.Current.ApplicationTheme = + ThemeManager.Current.ActualApplicationTheme == ApplicationTheme.Dark + ? ApplicationTheme.Light + : ApplicationTheme.Dark; + }; + } } } diff --git a/BililiveRecorder.WPF/Resources/IconResources.xaml b/BililiveRecorder.WPF/Resources/IconResources.xaml index 9fff6ef..6197c78 100644 --- a/BililiveRecorder.WPF/Resources/IconResources.xaml +++ b/BililiveRecorder.WPF/Resources/IconResources.xaml @@ -97,6 +97,9 @@ +