From aaa9036e8948030ccb1892c638c1eaba8721d951 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Sep 2021 20:28:42 +0200 Subject: [PATCH] Added DispatcherQueue dispatching for high contrast theme change --- Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs | 13 ++++++++----- .../XamlIslandsTest_ThemeListener_Threading.cs | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs b/Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs index 4d34da111b6..9db0cecac32 100644 --- a/Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs +++ b/Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs @@ -79,23 +79,26 @@ public ThemeListener(DispatcherQueue dispatcherQueue = null) } } - private void Accessible_HighContrastChanged(AccessibilitySettings sender, object args) + private async void Accessible_HighContrastChanged(AccessibilitySettings sender, object args) { #if DEBUG System.Diagnostics.Debug.WriteLine("HighContrast Changed"); #endif - UpdateProperties(); + await OnThemePropertyChangedAsync(); } // Note: This can get called multiple times during HighContrast switch, do we care? private async void Settings_ColorValuesChanged(UISettings sender, object args) { - await OnColorValuesChanged(); + await OnThemePropertyChangedAsync(); } - // Internal abstraction is used by the Unit Tests - internal Task OnColorValuesChanged() + /// + /// Dispatches an update for the public properties and the firing of on . + /// + /// A that indicates when the dispatching has completed. + internal Task OnThemePropertyChangedAsync() { // Getting called off thread, so we need to dispatch to request value. return DispatcherQueue.EnqueueAsync( diff --git a/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_ThemeListener_Threading.cs b/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_ThemeListener_Threading.cs index 61e73850b40..86ab15413fd 100644 --- a/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_ThemeListener_Threading.cs +++ b/UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_ThemeListener_Threading.cs @@ -39,7 +39,7 @@ public Task Init() [TestMethod] public async Task ThemeListenerDispatcherTestAsync() { - await _themeListener.OnColorValuesChanged(); + await _themeListener.OnThemePropertyChangedAsync(); await _taskCompletionSource.Task; } @@ -49,7 +49,7 @@ public async Task ThemeListenerDispatcherTestFromOtherThreadAsync() { await Task.Run(async () => { - await _themeListener.OnColorValuesChanged(); + await _themeListener.OnThemePropertyChangedAsync(); }); await _taskCompletionSource.Task; }