Repository navigation
Description
Bug Report
Summary
After upgrading from Uno.WinUI 6.5.x to 6.6.x, ThemeResource lookups return Light-theme values even after the application theme has been explicitly set to Dark. This is a regression introduced by the element-level theming and lazy theme resource evaluation features in 6.6.
Regression Introduced By
- PR Element-level theming #22803 —
feat: Element-level theme(merged 2026-03-20, @MartinZikmund) - PR feat: Lazy theme resource evaluation #22887 —
feat: Lazy theme resource evaluation(merged 2026-04-07, @MartinZikmund)
Both are present on release/stable/6.6.
Reproduction Evidence
Failing build: uno.csharpmarkup build 210415 — PR unoplatform/uno.csharpmarkup#879 (bumps Uno.WinUI from 6.5.153 → 6.6.5).
7 Failing Tests (all ThemeResourceTests, WASM)
| Test | Expected (Dark) | Actual (Light) |
|---|---|---|
When_ColorResource_Dark |
#4C33FF |
#30E7E8 |
When_StaticColorResource_Dark |
#4C33FF |
#30E7E8 |
When_BrushResource_Dark |
#4C33FF |
#30E7E8 |
When_StaticBrushResource_Dark |
#4C33FF |
#30E7E8 |
When_ThicknessResource_Dark |
4,4,4,4 |
2,2,2,2 |
When_StaticThicknessResource_Dark |
4,4,4,4 |
2,2,2,2 |
When_CornerRadiusResource_Dark |
8,8,8,8 |
4,4,4,4 |
All tests follow the same pattern:
- Set
Application.Current.RequestedTheme = ApplicationTheme.Dark(via Uno.ExtensionsThemeService.SetThemeAsync) - Resolve a
ThemeResource - Assert it returns the Dark dictionary value
Light tests pass. Only Dark tests fail, always returning the Light-theme value.
Root Cause Analysis
The behavioral change
In 6.5.x:
internal static ResourceKey GetActiveTheme() => Themes.Active;In 6.6.x (post PR #22803):
internal static ResourceKey GetActiveTheme() => Themes.RequestedThemeForSubTree;Where RequestedThemeForSubTree uses a static Stack<ResourceKey>:
public static ResourceKey RequestedThemeForSubTree =>
_requestedThemeForSubTree.Count > 0 ? _requestedThemeForSubTree.Peek() : Active;The mechanism
ThemeService.SetThemeAsync(Dark)correctly setsThemes.Active = "Dark"viaApplication.RequestedThemeForResources→ResourceDictionary.SetActiveTheme()NotifyThemeChangedCoredoes push/pop correctly in try/finally during the theme walkThemeResourceReference.RefreshValue()(from PR feat: Lazy theme resource evaluation #22887) callsdict.TryGetValue()which internally usesGetActiveTheme()→RequestedThemeForSubTree
Likely failure scenario
When the stack is empty, RequestedThemeForSubTree falls back to Active — so in theory it should work. However:
- The
NotifyThemeChangedCorecode has a fallback:Application.Current?.ActualElementTheme ?? ElementTheme.Light— this?? ElementTheme.Lightdefault could cause incorrect behavior ifApplication.Currentis null or hasn't propagated the theme yet - The
needsPushdecision compares the element's requested theme againstGetActiveTheme()— if the stack has a stale entry from a prior walk, subsequent elements might not push correctly - The static
Stack<ResourceKey>has no thread-safety guarantees, though on WASM this is less relevant (single-threaded)
Affected platforms
- WASM: Confirmed failing (build 210415)
- Skia: Likely affected (same
UNO_HAS_ENHANCED_LIFECYCLEdefine, same code path) - Others: Sanity checks needs to be done
Key Code Locations (release/stable/6.6)
| File | Key Code |
|---|---|
src/Uno.UI/UI/Xaml/ResourceDictionary.cs |
GetActiveTheme(), Themes class with RequestedThemeForSubTree, Push/Pop |
src/Uno.UI/UI/Xaml/FrameworkElement.Theming.cs |
NotifyThemeChangedCore — push/pop lifecycle, ?? ElementTheme.Light fallback |
src/Uno.UI/UI/Xaml/Application.cs |
RequestedThemeForResources setter → SetActiveTheme() |
src/Uno.UI/UI/Xaml/Data/ThemeResourceReference.cs |
RefreshValue() — pinned dict re-resolution using GetActiveTheme() |
src/Uno.UI/UI/Xaml/DependencyObjectStore.Theming.cs |
UpdateAllThemeReferences / UpdateThemeReference — calls RefreshValue() |
Expected Behavior
After Application.Current.RequestedTheme = ApplicationTheme.Dark, all ThemeResource lookups should resolve against the Dark theme dictionary — identical to 6.5.x behavior.
Impact
- Blocks uno.csharpmarkup 6.6 release (PR Docs - update tutorial link #879)
- Any app using
ThemeServiceor programmatic theme switching will get wrong colors in 6.6
Activity
[-]fix: ThemeResource resolution returns Light-theme values after switching to Dark in 6.6 (regression from element-level theming)[/-][+]ThemeResource resolution returns Light-theme values after switching to Dark in 6.6 (regression from element-level theming)[/+]fix(theming): split event/foreground guard from binding guard on firs…
fix: resolve ThemeResource not updating on first app theme switch
fix: set theme before raising ActualThemeChanged event
khaskoul commentedon May 12, 2026
The issue still occurs on
Templates/SDK: 6.6.10
Platform(s): Desktop
VS VSIX: 6.6.7.7
IDE: VS 18.4.6
OS: Windows
App used to test:
UnoApp5.zip
Recording.2026-05-12.104004.mp4
• Current theme: "Dark" (label updated correctly)
• Box color: Still cyan (#30E7E8) — the Light value
• Border: Still 2px — the Light value
• Corner radius: Still 4px — the Light value
This proves the regression: {ThemeResource} lookups are not re-resolving against the Dark dictionary after ThemeService.SetThemeAsync(Dark) is called.
The Themes.Active is being set (the app knows it's Dark), but GetActiveTheme() via RequestedThemeForSubTree is still returning the Light-theme key during resource resolution.
The overall page background also did not switch to a dark color, further confirming that all {ThemeResource} bindings are stuck on Light values — exactly matching the 7 failing tests in the CI build.
docs(theming): add WinUI-alignment refactor spec
docs(theming): add Phase 3 and Phase 4 handoff prompts
docs(theming): mark Phase 5 complete in progress tracker
55 remaining items
docs(theming): scope native to OS + application theme (element theme …
docs(theming): add Phase 6 handoff prompt
docs(theming): add WinUI-alignment refactor spec
docs(theming): add Phase 3 and Phase 4 handoff prompts
docs(theming): mark Phase 5 complete in progress tracker
docs(theming): scope native to OS + application theme (element theme …
docs(theming): add Phase 6 handoff prompt
agneszitte commentedon Jul 2, 2026
@khaskoul I am closing this issue as normally fixed with latest Uno.Sdk 6.6.14. I will let you confirm on your side and with HD as well, but with a quick test on my side:
jhanvi03 commentedon Jul 3, 2026
Reopening the issue, as it still appears to be reproducible with Hot Design.
Tested with:
Sdk/template: 6.6.14
Rider Plugin: 1.10.43
OS: Mac
TFM: Desktop
Screen.Recording.2026-07-03.at.11.50.04.AM.mov
MartinZikmund commentedon Jul 6, 2026
This is hot design specific problem. When you initially enter HD, it will put itself as the root element. This means that clicking the theme switch buttons changes the theme of HD, not the app inside. The behavior is in fact correct, although not what the user would expect. However, as long as the app is implemented in a way that is HD aware (eg. switching theme changes theme of the app's root element instead of HD root, it will behave correctly.
nickrandolph commentedon Jul 6, 2026
@MartinZikmund I concur, this is an issue that hasn't been resolved. It's actually an issue with extensions or toolkit themeservice that hasn't been updated to be ALC aware
cc @kazo0 @Kunal22shah
jhanvi03 commentedon Jul 6, 2026
Closing this issue as the underlying Uno core issue has been resolved.
The remaining behavior is specific to Hot Design and is being tracked separately in https://github.com/unoplatform/uno.hotdesign/issues/7104, where it will be addressed as part of the 6.7 release.