Skip to content

Overwriting accent color via SystemAccentColor key does not work #3555

Closed

Description

@MartinZikmund

Current behavior

When SystemAccentColor is overwritten, it is not applied to derived resources like SystemColorControlAccentBrush.

Expected behavior

Should apply the color to all derived resources.

How to reproduce it (as minimally and precisely as possible)

<Application
    x:Class="HealthApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:HealthApp">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
            </ResourceDictionary.MergedDictionaries>
            <Color x:Key="SystemAccentColor">#E64A19</Color>
        </ResourceDictionary>
    </Application.Resources>
</Application>

On main page:

 <Grid Background="{ThemeResource SystemColorControlAccentBrush}"></Grid>

Probable reason for the issue

In Generic.xaml, each theme has:

			<!-- Added manually (not part of UWP's SystemResources.xaml) -->
			<Color x:Key="SystemColorHighlightColor">#FF3399FF</Color>
			<Color x:Key="SystemAccentColor">#FF0078D7</Color>
			<SolidColorBrush x:Key="SystemColorControlAccentBrush"
					 Color="{StaticResource SystemAccentColor}" />

I guess the SystemAccentColor is set as StaticResource, and providing a custom one in does not overwrite it for SystemColorControlAccentBrush.

Workaround

Define the SystemColorControlAccentBrush manually as well in App.xaml:

<Color x:Key="SystemAccentColor">#E64A19</Color>
<SolidColorBrush x:Key="SystemColorControlAccentBrush"
					 Color="{StaticResource SystemAccentColor}" />

Environment

Nuget Package:

Package Version(s):

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
  • Build tasks
  • Solution Templates

Visual Studio:

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Activity

  1. added
    kind/bug
    triage/untriaged
    project/resources 🈷️
    on Jul 16, 2020
  2. removed
    triage/untriaged
    on Aug 28, 2020
  3. modified the milestone: 3.1 on Aug 29, 2020
  4. added
    project/styling 👔
    on Sep 21, 2020
  5. MartinZikmund commented on Nov 2, 2020

    @MartinZikmund
    MemberAuthor

    @davidjohnoliver actually it seems this could just about making sure the SystemColorControlAccentBrush and related use ThemeResource instead of StaticResource when referencing the accent color, correct?

  6. davidjohnoliver commented on Nov 2, 2020

    @davidjohnoliver
    Contributor

    @davidjohnoliver actually it seems this could just about making sure the SystemColorControlAccentBrush and related use ThemeResource instead of StaticResource when referencing the accent color, correct?

    That should hopefully do it, yes.

  7. added this to the 3.2 milestone on Nov 2, 2020
  8. MartinZikmund commented on Nov 4, 2020

    @MartinZikmund
    MemberAuthor

    It turns out this actually does work in the end. Overwriting just the Color is not possible, not even in UWP.

    What does work is to override the brushes:

    <Application.Resources>
        <SolidColorBrush x:Key="SystemControlHighlightAccentBrush" Color="Red" />
        <SolidColorBrush x:Key="SystemColorControlAccentBrush" Color="Red" />
    </Application.Resources>
    

    This properly overrides accent color and highlight accent color and these are then even reflected on controls like ToggleButton

  9. removed this from the 3.2 milestone on Nov 4, 2020
  10. davidjohnoliver commented on Apr 28, 2021

    @davidjohnoliver
    Contributor

    @MartinZikmund I'm not sure why you closed this issue? Putting the following App.Resources works on UWP, but not with Uno:

    <Color x:Key="SystemAccentColor">HotPink</Color>
    

    (eg to change checked background of CheckBox)

  11. MartinZikmund commented on Apr 28, 2021

    @MartinZikmund
    MemberAuthor

    Probably I did something wrong when testing on UWP back then. Reopening 👍

  12. added
    difficulty/medium 🤔
    on Jun 1, 2021
  13. added this to the 3.9 milestone on Jun 1, 2021
  14. removed this from the 3.9 milestone on Aug 11, 2021
  15. jeromelaban commented on Jan 27, 2022

    @jeromelaban
    Member

    Fixed in Uno latest, single-file merged dictionaries allow for the resolution to work as intended when using the resource explicitly, but it won't override the color when defined in fluent styles (even in WinUI).

    Closing for now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/medium 🤔kind/bugproject/resources 🈷️project/styling 👔

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions