Implement support for high contrast in mica controller sample#1879
Merged
marcelwgn merged 1 commit intomicrosoft:mainfrom May 23, 2025
Merged
Implement support for high contrast in mica controller sample#1879marcelwgn merged 1 commit intomicrosoft:mainfrom
marcelwgn merged 1 commit intomicrosoft:mainfrom
Conversation
Contributor
Author
|
/azp run |
niels9001
approved these changes
May 23, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request implements support for high contrast mode in the Mica Controller sample, addressing issue #1763.
- Updates the theme configuration by setting the IsHighContrast property based on ThemeSettings derived from the window’s AppWindow ID.
- Adds necessary using directives for Windows.UI.ViewManagement and Microsoft.UI.System to support the new high contrast API.
Comment on lines
+129
to
+130
| configurationSource = new SystemBackdropConfiguration(); | ||
| configurationSource.IsHighContrast = ThemeSettings.CreateForWindowId(this.AppWindow.Id).HighContrast; |
There was a problem hiding this comment.
The logic to set 'IsHighContrast' is duplicated between this line and line 207. Consider extracting this operation into a helper method to improve maintainability.
Suggested change
| configurationSource = new SystemBackdropConfiguration(); | |
| configurationSource.IsHighContrast = ThemeSettings.CreateForWindowId(this.AppWindow.Id).HighContrast; | |
| configurationSource = new SystemBackdropConfiguration(); | |
| configurationSource.IsHighContrast = GetIsHighContrast(); |
Comment on lines
+206
to
209
| configurationSource.IsHighContrast = ThemeSettings.CreateForWindowId(this.AppWindow.Id).HighContrast; | ||
| configurationSource.Theme = (SystemBackdropTheme)((FrameworkElement)Content).ActualTheme; | ||
| } | ||
|
|
There was a problem hiding this comment.
The repeated setting of 'IsHighContrast' here mirrors the logic at line 130. Extracting a dedicated method for this logic could reduce duplication and ease future updates.
Suggested change
| configurationSource.IsHighContrast = ThemeSettings.CreateForWindowId(this.AppWindow.Id).HighContrast; | |
| configurationSource.Theme = (SystemBackdropTheme)((FrameworkElement)Content).ActualTheme; | |
| } | |
| UpdateIsHighContrast(); | |
| configurationSource.Theme = (SystemBackdropTheme)((FrameworkElement)Content).ActualTheme; | |
| } | |
| private void UpdateIsHighContrast() | |
| { | |
| if (configurationSource != null) | |
| { | |
| configurationSource.IsHighContrast = ThemeSettings.CreateForWindowId(this.AppWindow.Id).HighContrast; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
We were not properly respecting high contrast in the Mica Controller sample.
Motivation and Context
Fixes #1763
How Has This Been Tested?
Screenshots (if appropriate):
Before: See #1763

After:
Types of changes