Repository navigation
fix(theming): ensure ThemeResource updates on first walk without spurious events - #23178
Conversation
Elements with stored theme == Theme.None were not getting their ThemeResource bindings updated on the first application-level theme change (e.g. Light → Dark). The special-casing of Theme.None in NotifyThemeChangedCore substituted the already-updated appBaseTheme, making themeChanged falsely evaluate to false. Fix: use Theming.GetBaseValue(oldTheme) unconditionally. Since GetBaseValue(None) returns None (0x00 & 0x03 = 0x00), which never equals Light or Dark, themeChanged is always true for uninitialized elements — matching MUX/WinUI behavior. Fixes #23177
There was a problem hiding this comment.
Pull request overview
Fixes a regression in Uno’s element-level theming theme-walk where elements with a stored theme of Theme.None would skip ThemeResource re-evaluation on the first application theme switch, leaving stale (Light) values after switching to Dark.
Changes:
- Adjust
FrameworkElement.NotifyThemeChangedCoreto computeoldBaseviaTheming.GetBaseValue(oldTheme)unconditionally, ensuring first-walk updates forTheme.None. - Add runtime regression tests validating
ThemeResourcevalues update correctly on app theme switches (including nested elements).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/FrameworkElement.Theming.cs | Fixes theme-walk change detection so Theme.None elements don’t incorrectly skip theme binding refresh on first app-theme change. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_ElementTheme.cs | Adds runtime tests covering app-level theme switching and ThemeResource updates (single element + nested elements). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
CI runners may default to Dark theme, causing tests to fail when they assert initial Light theme values. Added UseApplicationLightTheme() helper and use it at the start of both ThemeResource regression tests.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
|
|
…t walk Aligns with WinUI's framework.cpp RaiseActiveThemeChangedEventIfChanging which uses oldTheme == Theme::None ? GetBaseTheme() : GetBaseValue(oldTheme) to prevent spurious ActualThemeChanged events and foreground inheritance on the first theme walk, while still allowing UpdateThemeBindings to fire for elements that haven't been themed yet (fixes #23177).
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
…tests
Replace ResourceExtension (Toolkit-only class unavailable in Uno.UI)
with XamlReader.Load + inline ThemeDictionaries + {ThemeResource} markup,
matching the proven pattern used throughout the same test file.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
|
|
The SamplesApp runtime-test handler pins RequestedTheme=Light on the
outer Frame, so app-level theme changes cannot reach embedded test
content. Mark the two regression tests with [RequiresFullWindow] and
add an Assert.Fail guard in ThemeHelper.UseApplication{Dark,Light}Theme
so future tests fail fast with an actionable message instead of silently
seeing stale theme values.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
|
Other tests in Given_ElementTheme and Given_Window also call ThemeHelper.UseApplicationDarkTheme/UseApplicationLightTheme; without [RequiresFullWindow] the SamplesApp test runner's pinned Frame (RequestedTheme=Light) blocks app-level theme propagation and they would now fail the AssertFullWindowForApplicationTheme guard. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23178/wasm-skia-net9/index.html |
|
@Mergifyio backport release/stable/6.6 |
✅ Backports have been createdDetails
|
Adds runtime test covering the exact CSharpMarkup ThemeBindingProvider pattern: app-level theme change → ActualThemeChanged fires → handler reads ActualTheme to select theme dictionary → resolves resource. This test targets the combination not covered by existing tests: - When_AppTheme_Changes_ActualTheme_Returns_New_Value_In_Handler covers app-level theme (no resource resolution) - When_ThemeResource_Resolved_During_ActualThemeChanged_Returns_New_Value covers resource resolution (local RequestedTheme only) The new test validates both together, matching the real-world failure that caused the CSharpMarkup canary regression. Related to #23178, #23197
…6.6/pr-23178 fix(theming): ensure ThemeResource updates on first walk without spurious events (backport #23178)
Summary
Fixes #23177
Regression Introduced By
Splits the single
themeChangedguard inNotifyThemeChangedCoreinto two independent guards to correctly handle the first theme walk scenario:themeChanged=oldBase != newBase || forceRefresh— gatesUpdateThemeBindings. Always true on the first walk (Theme.None → Light/Dark), ensuring ThemeResource bindings resolve immediately.effectiveThemeChanged=oldBaseForEvent != newBase || forceRefresh— gates foreground inheritance andRaiseActualThemeChanged(). Uses WinUI's fallback pattern (oldTheme == Theme.None ? appBaseTheme : oldBase) to suppress spurious events when the effective theme hasn't actually changed.WinUI Alignment
This mirrors WinUI's
framework.cppRaiseActiveThemeChangedEventIfChangingwhich treatsTheme::Noneas equivalent to the app's base theme for the purpose of event/state changes, while still allowing resource resolution to proceed.What This Fixes
oldBase == newBasebeingNone == None).ActualThemeChangedevents fire on the initial theme walk.Test Infrastructure
ThemeHelper.UseApplicationLightTheme()to explicitly set Light theme at the start of tests (no reliance on CI default).ThemeHelper.AssertFullWindowForApplicationTheme()guard — fails fast with a clear message ifUseApplicationDarkTheme/UseApplicationLightThemeare called without[RequiresFullWindow], preventing silent false-passes caused by the SamplesApp test runner's pinnedRequestedTheme=LightFrame.[RequiresFullWindow]to all tests that change app-level theme (existing and new).When_AppTheme_Changes_ThemeResource_Values_UpdateandWhen_AppTheme_Changes_Nested_Elements_ThemeResources_Update.