Skip to content

fix(theming): ensure ThemeResource updates on first walk without spurious events (backport #23178) - #23195

Merged
agneszitte merged 8 commits into
release/stable/6.6from
mergify/bp/release/stable/6.6/pr-23178
May 11, 2026
Merged

agneszitte merged 8 commits into
release/stable/6.6from
mergify/bp/release/stable/6.6/pr-23178

Conversation

@mergify

@mergify mergify Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #23177

Regression Introduced By


Splits the single themeChanged guard in NotifyThemeChangedCore into two independent guards to correctly handle the first theme walk scenario:

  • themeChanged = oldBase != newBase || forceRefresh — gates UpdateThemeBindings. Always true on the first walk (Theme.None → Light/Dark), ensuring ThemeResource bindings resolve immediately.
  • effectiveThemeChanged = oldBaseForEvent != newBase || forceRefresh — gates foreground inheritance and RaiseActualThemeChanged(). 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.cpp RaiseActiveThemeChangedEventIfChanging which treats Theme::None as equivalent to the app's base theme for the purpose of event/state changes, while still allowing resource resolution to proceed.

What This Fixes

  • ThemeResource markup extensions now correctly update when the app theme is toggled for the first time (was previously blocked by oldBase == newBase being None == None).
  • No spurious ActualThemeChanged events fire on the initial theme walk.
  • Foreground inheritance only triggers when the effective theme genuinely changes.

Test Infrastructure

  • Added ThemeHelper.UseApplicationLightTheme() to explicitly set Light theme at the start of tests (no reliance on CI default).
  • Added ThemeHelper.AssertFullWindowForApplicationTheme() guard — fails fast with a clear message if UseApplicationDarkTheme / UseApplicationLightTheme are called without [RequiresFullWindow], preventing silent false-passes caused by the SamplesApp test runner's pinned RequestedTheme=Light Frame.
  • Added [RequiresFullWindow] to all tests that change app-level theme (existing and new).
  • Added two regression tests: When_AppTheme_Changes_ThemeResource_Values_Update and When_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.

agneszitte and others added 8 commits May 4, 2026 22:52
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)
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)
@agneszitte

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@agneszitte
agneszitte merged commit 764cdbf into release/stable/6.6 May 11, 2026
15 of 26 checks passed
@agneszitte
agneszitte deleted the mergify/bp/release/stable/6.6/pr-23178 branch May 11, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants