Skip to content

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

Merged
MartinZikmund merged 8 commits into
masterfrom
dev/agzi/fix-23177-themeresource-first-walk
May 4, 2026
Merged

MartinZikmund merged 8 commits into
masterfrom
dev/agzi/fix-23177-themeresource-first-walk

Conversation

@agneszitte

@agneszitte agneszitte commented May 2, 2026 •

Copy link
Copy Markdown
Member

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.

Copilot AI review requested due to automatic review settings May 2, 2026 02:37
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
@agneszitte
agneszitte marked this pull request as draft May 2, 2026 02:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.NotifyThemeChangedCore to compute oldBase via Theming.GetBaseValue(oldTheme) unconditionally, ensuring first-walk updates for Theme.None.
  • Add runtime regression tests validating ThemeResource values 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.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings May 2, 2026 04:44
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 210433 has failed on Uno.UI - CI.

…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).
@agneszitte agneszitte changed the title fix: Resolve ThemeResource not updating on first app theme switch fix(theming): ensure ThemeResource updates on first walk without spurious events May 2, 2026
@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 210450 has failed on Uno.UI - CI.

…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.
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 210454 has failed on Uno.UI - CI.

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]>
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 210561 has failed on Uno.UI - CI.

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]>
@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund marked this pull request as ready for review May 4, 2026 15:24
Copilot AI review requested due to automatic review settings May 4, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

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

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@agneszitte

Copy link
Copy Markdown
Member Author

@Mergifyio backport release/stable/6.6

@mergify

mergify Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.6

✅ Backports have been created

Details

@MartinZikmund
MartinZikmund merged commit e59b6ac into master May 4, 2026
45 checks passed
@MartinZikmund
MartinZikmund deleted the dev/agzi/fix-23177-themeresource-first-walk branch May 4, 2026 22:51
MartinZikmund pushed a commit that referenced this pull request May 7, 2026
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
agneszitte added a commit that referenced this pull request May 11, 2026
…6.6/pr-23178

fix(theming): ensure ThemeResource updates on first walk without spurious events (backport #23178)
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.

ThemeResource resolution returns Light-theme values after switching to Dark in 6.6 (regression from element-level theming)

5 participants