Repository navigation
fix(theming): resolve focus visual brush against element's effective theme - #23243
Conversation
…theme WinUI resolves the FocusVisualPrimaryBrush / FocusVisualSecondaryBrush default values against `targetObject->GetTheme()` (see microsoft-ui-xaml2 DependencyProperty.cpp::GetDefaultFocusVisualBrush). Uno was passing a null context to ResourceResolver.TryStaticRetrieval, which meant the lookup used the application-level active theme instead of the focused element's effective theme. When the app/system theme differed from a subtree's RequestedTheme, the focus visual rendered with the wrong theme's brushes. Push the focused element's theme onto the resource resolution stack (via ResourceDictionary.PushRequestedThemeForSubTree) before performing the static lookup, mirroring WinUI's behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes focus-visual default brush resolution so FocusVisualPrimaryBrush / FocusVisualSecondaryBrush are resolved against the focused element’s effective theme (including element/ancestor RequestedTheme overrides) rather than only the application-level theme, aligning behavior with WinUI and addressing #23242.
Changes:
- Updated
DependencyProperty.GetDefaultValueto resolve focus visual brush defaults under the element’s effective theme by temporarily pushing the theme onto the resource-resolution stack. - Added runtime regression tests validating focus visual brush defaults for Light/Dark subtree overrides against the app theme.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/DependencyProperty.cs |
Resolves default focus visual brushes under the element’s effective theme by pushing the appropriate theme key during static resource lookup. |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_FrameworkElement_FocusVisuals.cs |
Adds [RequiresFullWindow] runtime tests ensuring focus visual brushes follow element-level/ancestor RequestedTheme rather than app theme. |
💡 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-23243/wasm-skia-net9/index.html |
GitHub Issue: closes #23242
PR Type:
🐞 Bugfix
What changed? 🚀
DependencyProperty.GetDefaultValueresolved the default values forFocusVisualPrimaryBrush/FocusVisualSecondaryBrushviaResourceResolver.TryStaticRetrieval("SystemControlFocusVisual…Brush", null, …). Thenullcontext made the lookup pick whichever theme was currently active at the application level, so an element inside a subtree with an explicitRequestedThemedifferent fromApplication.Current.RequestedThemewould receive brushes from the wrong theme dictionary. The focus visual then rendered with system/app-theme colors instead of the focused element's effective theme.This change pushes the focused element's effective theme onto the resource resolution stack (
ResourceDictionary.PushRequestedThemeForSubTree) around the static lookup, matching WinUI'sCDependencyProperty::GetDefaultFocusVisualBrushwhich resolves againsttargetObject->GetTheme()(MUX reference:microsoft-ui-xaml2/src/dxaml/xcp/core/core/elements/DependencyProperty.cpp, lines 131-150 and 309-345).GetEffectiveThemeKeymirrorsFrameworkElement.ActualTheme's fallback chain (element_theme→Application.Current.ActualElementTheme→Light).PR Checklist ✅
Screenshots Compare Test Runresults.Tests added
Five new
[RequiresFullWindow]runtime tests inGiven_FrameworkElement_FocusVisualscover:RequestedTheme=Lightwhile app is Dark → primary brush is Light (#E4000000).RequestedTheme=Darkwhile app is Light → primary brush is Dark (#FFFFFFFF).#B3FFFFFFLight /#B3000000Dark).RequestedTheme=Lightwhile app is Dark → primary brush is Light.All 10 tests in the class pass on Skia Desktop (5 existing + 5 new).