Repository navigation
fix(theming): ensure ThemeResource updates on first walk without spurious events (backport #23178) - #23195
Merged
agneszitte merged 8 commits intoMay 11, 2026
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 (cherry picked from commit 46f91b9)
(cherry picked from commit 89c7ebd)
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. (cherry picked from commit 89459fe)
…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). (cherry picked from commit 625ee04)
…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.
(cherry picked from commit b86c837)
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]>
(cherry picked from commit 3c47e3b)
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]> (cherry picked from commit 6dedaed)
(cherry picked from commit dec8c99)
Member
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.This is an automatic backport of pull request fix(theming): ensure ThemeResource updates on first walk without spurious events #23178 done by Mergify.