Skip to content

Implement support for high contrast in mica controller sample - #1879

Merged
Marcel W. (marcelwgn) merged 1 commit into
microsoft:mainfrom
marcelwgn:high-contrast-mica-controller
May 23, 2025
Merged

Marcel W. (marcelwgn) merged 1 commit into
microsoft:mainfrom
marcelwgn:high-contrast-mica-controller

Conversation

@marcelwgn

Copy link
Copy Markdown
Contributor

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:
Screenshot of the sample window respecting high contrast like the applications behind it.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
@marcelwgn
Marcel W. (marcelwgn) enabled auto-merge (squash) May 16, 2025 14:26
@marcelwgn

Copy link
Copy Markdown
Contributor Author

/azp run

@marcelwgn
Marcel W. (marcelwgn) merged commit 7eead05 into microsoft:main May 23, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copilot AI May 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copilot uses AI. Check for mistakes.
Comment on lines +206 to 209
configurationSource.IsHighContrast = ThemeSettings.CreateForWindowId(this.AppWindow.Id).HighContrast;
configurationSource.Theme = (SystemBackdropTheme)((FrameworkElement)Content).ActualTheme;
}

Copilot AI May 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}
}
Copilot uses AI. Check for mistakes.
@marcelwgn
Marcel W. (marcelwgn) deleted the high-contrast-mica-controller branch May 26, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants