Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DispatcherQueue dispatching for high contrast theme change #4243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
/// <summary>
/// Dispatches an update for the public properties and the firing of <see cref="ThemeChanged"/> on <see cref="DispatcherQueue"/>.
/// </summary>
/// <returns>A <see cref="Task"/> that indicates when the dispatching has completed.</returns>
internal Task OnThemePropertyChangedAsync()
{
// Getting called off thread, so we need to dispatch to request value.
return DispatcherQueue.EnqueueAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Task Init()
[TestMethod]
public async Task ThemeListenerDispatcherTestAsync()
{
await _themeListener.OnColorValuesChanged();
await _themeListener.OnThemePropertyChangedAsync();

await _taskCompletionSource.Task;
}
Expand All @@ -49,7 +49,7 @@ public async Task ThemeListenerDispatcherTestFromOtherThreadAsync()
{
await Task.Run(async () =>
{
await _themeListener.OnColorValuesChanged();
await _themeListener.OnThemePropertyChangedAsync();
});
await _taskCompletionSource.Task;
}
Expand Down