diff --git a/WinUIGallery/Helpers/TitleBarHelper.cs b/WinUIGallery/Helpers/TitleBarHelper.cs index b0b5088e1..bb56e0a2b 100644 --- a/WinUIGallery/Helpers/TitleBarHelper.cs +++ b/WinUIGallery/Helpers/TitleBarHelper.cs @@ -19,8 +19,6 @@ public static Windows.UI.Color ApplySystemThemeToCaptionButtons(Window window, E public static void SetCaptionButtonColors(Window window, Windows.UI.Color color) { - var res = Application.Current.Resources; - res["WindowCaptionForeground"] = color; window.AppWindow.TitleBar.ButtonForegroundColor = color; } diff --git a/WinUIGallery/MainWindow.xaml.cs b/WinUIGallery/MainWindow.xaml.cs index e2509348d..fa87b89a5 100644 --- a/WinUIGallery/MainWindow.xaml.cs +++ b/WinUIGallery/MainWindow.xaml.cs @@ -14,7 +14,6 @@ using System.Threading; using System.Threading.Tasks; using Windows.Foundation; -using Windows.UI.ViewManagement; using WinUIGallery.Helpers; using WinUIGallery.Models; using WinUIGallery.Pages; @@ -25,7 +24,6 @@ public sealed partial class MainWindow : Window { public Windows.System.VirtualKey ArrowKey; public Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue; - private UISettings _settings; public NavigationView NavigationView { @@ -38,14 +36,14 @@ public MainWindow() { this.InitializeComponent(); SetWindowProperties(); + RootGrid.ActualThemeChanged += (_,_) => TitleBarHelper.ApplySystemThemeToCaptionButtons(this, RootGrid.ActualTheme); dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); } private void RootGrid_Loaded(object sender, RoutedEventArgs e) { NavigationOrientationHelper.UpdateNavigationViewForElement(NavigationOrientationHelper.IsLeftMode()); - _settings = new UISettings(); - _settings.ColorValuesChanged += _settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event because the triggerTitleBarRepaint workaround no longer works + TitleBarHelper.ApplySystemThemeToCaptionButtons(this, RootGrid.ActualTheme); } private void SetWindowProperties() @@ -99,16 +97,6 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e) { throw new Exception("Failed to load Page " + e.SourcePageType.FullName); } - // this handles updating the caption button colors correctly when windows system theme is changed - // while the app is open - private void _settings_ColorValuesChanged(UISettings sender, object args) - { - // This calls comes off-thread, hence we will need to dispatch it to current app's thread - dispatcherQueue.TryEnqueue(() => - { - _ = TitleBarHelper.ApplySystemThemeToCaptionButtons(this, rootFrame.ActualTheme); - }); - } // Wraps a call to rootFrame.Navigate to give the Page a way to know which NavigationRootPage is navigating. // Please call this function rather than rootFrame.Navigate to navigate the rootFrame.