Repository navigation
fix(theming): set theme before raising ActualThemeChanged event - #23197
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Uno's theming pipeline so FrameworkElement.ActualTheme is persisted before ActualThemeChanged is raised, aligning the event behavior with the intended WinUI ordering and addressing the follow-up regression from #23178 / issue #23177.
Changes:
- Reorder
NotifyThemeChangedCoresoSetTheme(theme)runs beforeRaiseActualThemeChanged(). - Add regression tests for element-level and application-level theme changes to verify
ActualThemeduringActualThemeChanged.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/FrameworkElement.Theming.cs |
Adjusts theme-walk ordering so the stored theme is updated before the event is raised. |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_ElementTheme.cs |
Adds regression tests covering ActualThemeChanged behavior for subtree and app-level theme changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 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.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
992e54d to
aca45d8
Compare
Reorder SetRequestedTheme to apply the new theme value before propagating ActualThemeChanged to children, ensuring handlers observe the correct ActualTheme and resolve the right ThemeResource values. - Move SetTheme call before RaiseActualThemeChangedOnChildren - Add runtime tests covering event ordering, stale-theme regression, and ThemeResource resolution inside the handler Fixes #23177
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 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-23197/wasm-skia-net9/index.html |
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
|
@Mergifyio backport release/stable/6.6 |
✅ Backports have been createdDetails
|
…6.6/pr-23197 fix(theming): set theme before raising ActualThemeChanged event (backport #23197)
Summary
Follow-up to #23178 Related to #23177
Moves
SetTheme(theme)before bothPropagateThemeToChildrenandRaiseActualThemeChanged()inNotifyThemeChangedCoreso thatActualThemereturns the new value insideActualThemeChangedevent handlers.What was wrong
After PR #23178 (related to previous #22803 and #22887),
SetTheme(theme)was called afterRaiseActualThemeChanged(). This meant that readingActualThemeinside anActualThemeChangedhandler returned the old/stale theme instead of the new one.See, related C# Markup Canary Tests failing for more context
WinUI alignment
WinUI's
framework.cppcallsCUIElement::NotifyThemeChangedCore(theme)(which sets the theme) beforeRaiseActiveThemeChangedEventIfChanging(theme)(which fires the event). This fix aligns Uno with that ordering.Why moving SetTheme earlier is safe
oldThemeis already captured at the top ofNotifyThemeChangedCoreUpdateThemeBindingsandPropagateThemeToChildrenuse the passedthemeparameter, not the stored theme_themefield, not the parent'sTests added
When_ActualThemeChanged_Fires_ActualTheme_Returns_New_Value— verifies parent and childActualThemereturnDarkinsideActualThemeChangedhandler whenRequestedThemeis set toDark, and that the parent'sActualThemeis already updated when observed from the child's handlerWhen_AppTheme_Changes_ActualTheme_Returns_New_Value_In_Handler— verifiesActualThemereturnsDarkduring app-level theme change viaThemeHelper.UseApplicationDarkTheme()(exercises root→child propagation path)When_ThemeResource_Resolved_During_ActualThemeChanged_Returns_New_Value— verifies that a localThemeDictionariesresource resolves to the new theme's value when looked up viaActualThemeinsideActualThemeChanged(mimics the C# MarkupThemeBindingProviderpattern that triggered the original failure)