question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accent color is not overridable by setting SystemAccentColor or ColorPaletteResources

See original GitHub issue

Describe 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: Screenshot 2021-11-28 223030

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:open
  • Created 2 years ago
  • Reactions:7
  • Comments:5

github_iconTop GitHub Comments

3reactions
WelterDevelopmentcommented, Nov 28, 2021

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 and
  • SystemAccentColorDark1 in Light Mode

So I found my workaround to be:

  • Declare SystemAccentColorLight2 and SystemAccentColorDark1 in App.xaml
  • Update the Accent color at Runtime via c# with
    • Application.Current.Resources["SystemAccentColorLight2"] = SomeLightColor;
    • Application.Current.Resources["SystemAccentColorDark1"] = SomeDarkColor;
  • The very ugly workaround “ReloadPageTheme” (Using ColorPaletteResources in code-behind) seems to be still necessary in WinAppSDK 1.0 / WinUI 3.0
1reaction
Jhngrntncommented, Jul 13, 2023

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>

Read more comments on GitHub >

github_iconTop 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 >
ColorPaletteResources.Accent Property - Windows
Gets or sets the Accent color value.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found