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

App crashes when high contrast mode is enabled in Windows in .NET 9 with fluent themes enabled #10043

Open
aquinn39 opened this issue Nov 8, 2024 · 1 comment

Comments

@aquinn39
Copy link

aquinn39 commented Nov 8, 2024

Description

When enabling fluent themes in WPF in .NET 9 and high contrast mode is on in Windows, or fluent themes are already enabled and then high contrast mode is enabled, the app will crash with a System.Windows.Markup.XamlParseException. The full exception is:

System.Windows.Markup.XamlParseException: 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.'

ArgumentException: Item has already been added. Key in dictionary: 'SystemColorWindowColorBrush'  Key being added: 'SystemColorWindowColorBrush'

Image

Reproduction Steps

  1. Create a new WPF project and set it to use .NET 9
  2. Enable fluent themes in the project as described here: https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview4/wpf.md#support-for-windows-11-theming
  3. Enable high contrast mode in Windows
  4. Build and run the app
  5. Observe that it crashes
  6. Alternatively, swap step 3 and 4 around

Expected behavior

The app should not crash.

Actual behavior

The app crashes.

Regression?

Yes, not an issue with the old themes and older versions of .NET nor .NET Framework.

Known Workarounds

Enable the fluent themes using the Application.ThemeMode property within a try catch. App will still crash once the themes are enabled and the user turns on high contrast mode, but not if it was already on.

Impact

WPF cannot be used with the fluent themes while high contrast mode is enabled on the system.

Configuration

.NET 9, AnyCPU, Windows 11 build 22631.4037.

Other information

No response

@aquinn39
Copy link
Author

Still happens in .NET 9 😬. Honestly not sure how it got released in this state...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants