Accent color is not overridable by setting SystemAccentColor or ColorPaletteResources
See original GitHub issueDescribe the bug
The accent color seems to be fixed/readonly/hardcoded in WinAppSDK 1.0 / WinUI 3.0. It is not overridable by the usual techniques.
Steps to reproduce the bug
- Create a WinAppSDK 1.0 WAP project
- Replace the Ressources in App.xaml with:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ColorPaletteResources Accent="Blue" />
</ResourceDictionary.MergedDictionaries>
<Color x:Key="SystemAccentColor">Red</Color>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<Color x:Key="SystemAccentColor">Green</Color>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<Color x:Key="SystemAccentColor">Magenta</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
- Replace the Content of MainWindow.xaml with:
<Grid Background="DarkGray" RequestedTheme="Dark">
<ToggleButton HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="myButton" IsChecked="True">Click Me</ToggleButton>
</Grid>
Expected behavior
- It would be nice if at least one of the methods of overriding the accent color would work.
- It seems like the official Windows App SDK documentation tells us lies (Overriding the accent color)!?
Screenshots
- As you can see, my system’s accent color is used, and none of my overrides from App.xaml work:
NuGet package version
WinUI 3 - Windows App SDK 1.0 (If you’re seeing your issue in older previews of WinUI 3, please try this release)
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
Insider Build (xxxxx)
Additional context
Tested on Windows 11 Insider Build 22504.1010
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:5
Top Results From Across the Web
How to override user accent color in UWP app
I'm still not sure why the accent colour generated by Fluent Theme editor is not being applied though. One way to fix this,...
Read more >Using a Dynamic System Accent Color in UWP
This article describes an algorithm that allows individual pages in a XAML UWP app to override the system accent color.
Read more >Help me find the best way to conditionally override SwiftUI. ...
Anyway, .accentColor(:) modifier passing Color.accentColor or nil do not inherit the accent color from parent, it set it to blue.
Read more >Restart/fluent-xaml-theme-editor
Primary – This is essentially the Accent color and should contrast with mainly white text. It is also used in more choice locations...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems that ColorpaletteResource does nothing to the new WinUI 3.0 controls. Normally it should calculate all shades of SystemAccentColor automatically. And setting SystemAccentColor does nothing because the new WinUI 3.0 AccentBrushes seem to be based on:
SystemAccentColorLight2
in Dark Mode andSystemAccentColorDark1
in Light ModeSo I found my workaround to be:
Application.Current.Resources["SystemAccentColorLight2"] = SomeLightColor;
Application.Current.Resources["SystemAccentColorDark1"] = SomeDarkColor;
If using WinUI 3, I found it was important to call it a “Color” rather than “SolidColorBrush”. Otherwise, it won’t work.
<Color x:Key="SystemAccentColorLight1">#aeb5f2</Color>
<Color x:Key="SystemAccentColorLight2">#8993ec</Color>
<Color x:Key="SystemAccentColorLight3">#6571e6</Color>