Repository navigation
fix(theming): set theme before raising ActualThemeChanged event (backport #23197) - #23246
Merged
agneszitte merged 1 commit intoMay 11, 2026
Merged
Conversation
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 (cherry picked from commit aca45d8)
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
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)This is an automatic backport of pull request fix(theming): set theme before raising ActualThemeChanged event #23197 done by Mergify.