From 81f096669cddbb7a748712512e0f0484b9d345b6 Mon Sep 17 00:00:00 2001 From: tian Date: Sun, 29 Mar 2026 12:44:54 +0800 Subject: [PATCH] fix(windows): unify standard window title bar theming --- .../Views/MouseCalibrationWindow.xaml.cs | 26 +++++++++++++++++ .../Views/NotificationSettingsWindow.xaml.cs | 26 +++++++++++++++++ .../KeyStats/Views/SettingsWindow.xaml.cs | 28 ++++++++++++++++++- .../KeyStats/Views/StatsPopupWindow.xaml | 3 +- .../KeyStats/Views/StatsPopupWindow.xaml.cs | 5 ++++ 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/KeyStats.Windows/KeyStats/Views/MouseCalibrationWindow.xaml.cs b/KeyStats.Windows/KeyStats/Views/MouseCalibrationWindow.xaml.cs index 81014eb..36ff7a6 100644 --- a/KeyStats.Windows/KeyStats/Views/MouseCalibrationWindow.xaml.cs +++ b/KeyStats.Windows/KeyStats/Views/MouseCalibrationWindow.xaml.cs @@ -4,7 +4,9 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Threading; +using KeyStats.Helpers; using KeyStats.Services; namespace KeyStats.Views; @@ -31,6 +33,30 @@ public MouseCalibrationWindow() Interval = TimeSpan.FromMilliseconds(33) }; _liveTimer.Tick += (_, _) => UpdateLiveDistance(); + Loaded += OnLoaded; + Closed += OnClosed; + ThemeManager.Instance.ThemeChanged += OnThemeChanged; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + ApplyWindowTitleBarTheme(); + } + + private void OnClosed(object? sender, EventArgs e) + { + ThemeManager.Instance.ThemeChanged -= OnThemeChanged; + } + + private void OnThemeChanged() + { + Dispatcher.BeginInvoke(new Action(ApplyWindowTitleBarTheme)); + } + + private void ApplyWindowTitleBarTheme() + { + var handle = new WindowInteropHelper(this).Handle; + NativeInterop.TrySetImmersiveDarkMode(handle, ThemeManager.Instance.IsDarkTheme); } private void LoadSettings() diff --git a/KeyStats.Windows/KeyStats/Views/NotificationSettingsWindow.xaml.cs b/KeyStats.Windows/KeyStats/Views/NotificationSettingsWindow.xaml.cs index 6f1ebb2..fcdacdb 100644 --- a/KeyStats.Windows/KeyStats/Views/NotificationSettingsWindow.xaml.cs +++ b/KeyStats.Windows/KeyStats/Views/NotificationSettingsWindow.xaml.cs @@ -1,6 +1,8 @@ using System.Text.RegularExpressions; using System.Windows; using System.Windows.Input; +using System.Windows.Interop; +using KeyStats.Helpers; using KeyStats.Services; namespace KeyStats.Views; @@ -14,6 +16,30 @@ public NotificationSettingsWindow() InitializeComponent(); LoadSettings(); _isLoading = false; + Loaded += OnLoaded; + Closed += OnClosed; + ThemeManager.Instance.ThemeChanged += OnThemeChanged; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + ApplyWindowTitleBarTheme(); + } + + private void OnClosed(object? sender, System.EventArgs e) + { + ThemeManager.Instance.ThemeChanged -= OnThemeChanged; + } + + private void OnThemeChanged() + { + Dispatcher.BeginInvoke(new System.Action(ApplyWindowTitleBarTheme)); + } + + private void ApplyWindowTitleBarTheme() + { + var handle = new WindowInteropHelper(this).Handle; + NativeInterop.TrySetImmersiveDarkMode(handle, ThemeManager.Instance.IsDarkTheme); } private void LoadSettings() diff --git a/KeyStats.Windows/KeyStats/Views/SettingsWindow.xaml.cs b/KeyStats.Windows/KeyStats/Views/SettingsWindow.xaml.cs index dc62b9c..5dc1e00 100644 --- a/KeyStats.Windows/KeyStats/Views/SettingsWindow.xaml.cs +++ b/KeyStats.Windows/KeyStats/Views/SettingsWindow.xaml.cs @@ -1,5 +1,7 @@ -using System.Diagnostics; +using System.Diagnostics; using System.Windows; +using System.Windows.Interop; +using KeyStats.Helpers; namespace KeyStats.Views; @@ -10,6 +12,30 @@ public partial class SettingsWindow : Window public SettingsWindow() { InitializeComponent(); + Loaded += OnLoaded; + Closed += OnClosed; + ThemeManager.Instance.ThemeChanged += OnThemeChanged; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + ApplyWindowTitleBarTheme(); + } + + private void OnClosed(object? sender, System.EventArgs e) + { + ThemeManager.Instance.ThemeChanged -= OnThemeChanged; + } + + private void OnThemeChanged() + { + Dispatcher.BeginInvoke(new System.Action(ApplyWindowTitleBarTheme)); + } + + private void ApplyWindowTitleBarTheme() + { + var handle = new WindowInteropHelper(this).Handle; + NativeInterop.TrySetImmersiveDarkMode(handle, ThemeManager.Instance.IsDarkTheme); } private void OpenStats_Click(object sender, RoutedEventArgs e) diff --git a/KeyStats.Windows/KeyStats/Views/StatsPopupWindow.xaml b/KeyStats.Windows/KeyStats/Views/StatsPopupWindow.xaml index a6b1341..bac0209 100644 --- a/KeyStats.Windows/KeyStats/Views/StatsPopupWindow.xaml +++ b/KeyStats.Windows/KeyStats/Views/StatsPopupWindow.xaml @@ -22,7 +22,8 @@ -