Repository navigation
Description
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 byCResourceDictionary::CreateSystemColors). It adds aColorand aSolidColorBrushperGetColorAndBrushResourceInfoList()entry, plusIsApplicationFocusVisualKindReveal.- It never walks app or Fluent dictionaries and never touches HighContrast theme dictionaries.
CResourceDictionary::GetKeyFromGlobalThemeResourceNoRef(Resources.cpp) looks in system colors first, letsApplication.Resourcesoverride them (GetKeyOverrideFromApplicationResourcesNoRef), and then falls back to global theme resources.- It also has a
wasFirstCreateForResourcesshort-circuit inNotifyThemeChange, which Uno currently leaves commented out.
Why is this needed? 🤔
- Parity: Uno matches WinUI's high-contrast values but not its mechanism. Resource precedence between system colors and
Application.Resourcesis decided by lookup order in WinUI, while Uno overwrites dictionary values. - Performance: the walk materializes theme dictionaries the app never uses. perf(theming): Startup builds theme dictionaries the app never uses (~922 KB before first frame) #24538 / perf(theming): Cut ~922 KB of boot allocation from theme dictionary materialization #24539 mitigates this for the non-high-contrast case with an override counter. Porting the dedicated dictionary removes the walk, the override table and the counter entirely.
- Simplicity: no restore bookkeeping and no
ConditionalWeakTablestate to keep consistent across high-contrast on/off transitions.
Renderer 🎨
- Skia
- Native
For which platforms 📱💻🖥️
All platforms 🌍
Anything else we need to know? 💬
- Follow-up to perf(theming): Startup builds theme dictionaries the app never uses (~922 KB before first frame) #24538 / perf(theming): Cut ~922 KB of boot allocation from theme dictionary materialization #24539 (the counter-based skip is the interim mitigation).
- Existing coverage to keep green: runtime tests
Given_HighContrastAdjustmentandGiven_Theme_Materialization, and the high-contrast unit tests inGiven_ResourceDictionary.
Activity
MartinZikmund commentedon Nov 21, 2026
Scope addition after the accent color work in #22851. Checked against WinUI 2.7.0.
SystemResources.xamlshould go away as part of this. WinUI has no XAML file for these keys.CResourceDictionary::CreateSystemColorscreates an empty, flat dictionary,CCoreServices::UpdateColorAndBrushResourcesrefills it in code on every theme change, and lookup falls back to it viaGetSystemColorsResources(Resources.cpp).generic.xamlonly referencesSystemAccentColor*/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.xamlis a static stand-in:Default/Light/HighContrasttheme dictionaries with placeholder values that code then patches in place. After #22851 there are two patch passes inCoreServices.NotifyThemeChange:ResourceResolver.UpdateSystemColorAndBrushResources(high contrast, described above)ResourceResolver.UpdateSystemAccentColorAndBrushResources(accent entries, i.e. the non-OverrideAlphaitems ofFrameworkTheming.GetColorAndBrushResourceInfoList()), which writes intoSystemResources.xaml's theme dictionariesPorting 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/SliderHorizontalThumbHeightCheck them against WinUI's
generic.xaml/ theme resources and move or drop them accordingly. The file is also listed as non-merged insrc/Uno.UI/XamlMerge.targets.Extra coverage to keep green:
Given_UISettings_Accent(runtime) and theFeatureConfiguration.AccentColor.OverrideAccentColorpath.