Skip to content

Commit 9d9800d

Browse files
author
msftbot[bot]
authored
Added DispatcherQueue dispatching for high contrast theme change (#4243)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> <!-- 👉 It is imperative to resolve ONE ISSUE PER PR and avoid making multiple changes unless the changes interrelate with each other --> <!-- 📝 Please always keep the "☑️ Allow edits by maintainers" button checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 --> ## Fixes #3253 Applying changes discussed in #3253 (comment). <!-- Add the relevant issue number after the word "Fixes" mentioned above (for ex: "## Fixes #1234") which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more options below that apply to this PR. --> - Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? Changes to the high contrast theme are propagated on the original synchronization context. <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> ## What is the new behavior? The event handler now dispatches on the current dispatcher queue. <!-- Describe how was this issue resolved or changed? --> ## PR Checklist Please check if your PR fulfills the following requirements: <!-- and remove the ones that are not applicable to the current PR --> - [X] Tested code with current [supported SDKs](../#supported) - [X] New component - [X] Pull Request has been submitted to the documentation repository [instructions](../blob/main/Contributing.md#docs). Link: <!-- docs PR link --> - [X] Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that) - [X] If control, added to Visual Studio Design project - [X] Sample in sample app has been added / updated (for bug fixes / features) - [X] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/CommunityToolkit/WindowsCommunityToolkit-design-assets) - [X] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/CommunityToolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run _build/UpdateHeaders.bat_) - [X] Contains **NO** breaking changes
2 parents 03c3f3c + aaa9036 commit 9d9800d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,26 @@ public ThemeListener(DispatcherQueue dispatcherQueue = null)
7979
}
8080
}
8181

82-
private void Accessible_HighContrastChanged(AccessibilitySettings sender, object args)
82+
private async void Accessible_HighContrastChanged(AccessibilitySettings sender, object args)
8383
{
8484
#if DEBUG
8585
System.Diagnostics.Debug.WriteLine("HighContrast Changed");
8686
#endif
8787

88-
UpdateProperties();
88+
await OnThemePropertyChangedAsync();
8989
}
9090

9191
// Note: This can get called multiple times during HighContrast switch, do we care?
9292
private async void Settings_ColorValuesChanged(UISettings sender, object args)
9393
{
94-
await OnColorValuesChanged();
94+
await OnThemePropertyChangedAsync();
9595
}
9696

97-
// Internal abstraction is used by the Unit Tests
98-
internal Task OnColorValuesChanged()
97+
/// <summary>
98+
/// Dispatches an update for the public properties and the firing of <see cref="ThemeChanged"/> on <see cref="DispatcherQueue"/>.
99+
/// </summary>
100+
/// <returns>A <see cref="Task"/> that indicates when the dispatching has completed.</returns>
101+
internal Task OnThemePropertyChangedAsync()
99102
{
100103
// Getting called off thread, so we need to dispatch to request value.
101104
return DispatcherQueue.EnqueueAsync(

UnitTests/UnitTests.XamlIslands.UWPApp/XamlIslandsTest_ThemeListener_Threading.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Task Init()
3939
[TestMethod]
4040
public async Task ThemeListenerDispatcherTestAsync()
4141
{
42-
await _themeListener.OnColorValuesChanged();
42+
await _themeListener.OnThemePropertyChangedAsync();
4343

4444
await _taskCompletionSource.Task;
4545
}
@@ -49,7 +49,7 @@ public async Task ThemeListenerDispatcherTestFromOtherThreadAsync()
4949
{
5050
await Task.Run(async () =>
5151
{
52-
await _themeListener.OnColorValuesChanged();
52+
await _themeListener.OnThemePropertyChangedAsync();
5353
});
5454
await _taskCompletionSource.Task;
5555
}

0 commit comments

Comments
 (0)