Skip to content

Port WinUI SystemColorsResources for system/high-contrast colors instead of patching the dictionary graph #24767

Open

Description

@MartinZikmund

What would you like to be added? 💡

Port WinUI's SystemColorsResources mechanism for system colors and brushes (including high contrast) and remove Uno's walk-and-patch approach in ResourceResolver.UpdateSystemColorAndBrushResources.

Uno today: CoreServices.NotifyThemeChange() (src/Uno.UI/UI/Xaml/Internal/CoreServices.Theming.cs) calls ResourceResolver.UpdateSystemColorAndBrushResources(..., restoreDefaults: !HasHighContrastTheme()). It walks the whole merged-dictionary graph and probes the HighContrast, HighContrastBlack, HighContrastWhite and HighContrastCustom theme dictionaries on every node, which materializes lazy dictionaries. It overwrites system color and brush entries in place and records the overrides in a ConditionalWeakTable, so a later call can restore them.

WinUI (checked against release 2.5.1):

  • CCoreServices::UpdateColorAndBrushResources (dxaml/xcp/core/dll/xcpcore.cpp) clears and refills one dedicated dictionary, m_pSystemColorsResources (created by CResourceDictionary::CreateSystemColors). It adds a Color and a SolidColorBrush per GetColorAndBrushResourceInfoList() entry, plus IsApplicationFocusVisualKindReveal.
  • It never walks app or Fluent dictionaries and never touches HighContrast theme dictionaries.
  • CResourceDictionary::GetKeyFromGlobalThemeResourceNoRef (Resources.cpp) looks in system colors first, lets Application.Resources override them (GetKeyOverrideFromApplicationResourcesNoRef), and then falls back to global theme resources.
  • It also has a wasFirstCreateForResources short-circuit in NotifyThemeChange, which Uno currently leaves commented out.

Why is this needed? 🤔

Renderer 🎨

  • Skia
  • Native

For which platforms 📱💻🖥️

All platforms 🌍

Anything else we need to know? 💬

Activity

  1. added
    kind/enhancement
    triage/untriaged
    on Sep 26, 2026
  2. added
    7.1
    on Oct 14, 2026
  3. removed
    7.1
    on Oct 29, 2026
  4. MartinZikmund commented on Nov 21, 2026

    @MartinZikmund
    MemberAuthor

    Scope addition after the accent color work in #22851. Checked against WinUI 2.7.0.

    SystemResources.xaml should go away as part of this. WinUI has no XAML file for these keys. CResourceDictionary::CreateSystemColors creates an empty, flat dictionary, CCoreServices::UpdateColorAndBrushResources refills it in code on every theme change, and lookup falls back to it via GetSystemColorsResources (Resources.cpp). generic.xaml only references SystemAccentColor* / SystemColor*Color; it never defines them. The only XAML path upstream (m_strSystemColorsResourcesXaml) is a test-only injection hook.

    Uno's src/Uno.UI/UI/Xaml/Style/Generic/SystemResources.xaml is a static stand-in: Default / Light / HighContrast theme dictionaries with placeholder values that code then patches in place. After #22851 there are two patch passes in CoreServices.NotifyThemeChange:

    1. ResourceResolver.UpdateSystemColorAndBrushResources (high contrast, described above)
    2. ResourceResolver.UpdateSystemAccentColorAndBrushResources (accent entries, i.e. the non-OverrideAlpha items of FrameworkTheming.GetColorAndBrushResourceInfoList()), which writes into SystemResources.xaml's theme dictionaries

    Porting the dedicated system colors dictionary replaces both passes.

    What needs a new home when the file is removed (not system colors, just parked there):

    • ProgressBarBorderThemeThickness (per theme)
    • SliderHorizontalThumbWidth / SliderHorizontalThumbHeight

    Check them against WinUI's generic.xaml / theme resources and move or drop them accordingly. The file is also listed as non-merged in src/Uno.UI/XamlMerge.targets.

    Extra coverage to keep green: Given_UISettings_Accent (runtime) and the FeatureConfiguration.AccentColor.OverrideAccentColor path.

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

Metadata

Metadata

Assignees

Labels

kind/enhancementtriage/untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions