Skip to content

fix(theming): resolve focus visual brush against element's effective theme - #23243

Merged
MartinZikmund merged 1 commit into
masterfrom
dev/mazi/focustheming
May 17, 2026
Merged

MartinZikmund merged 1 commit into
masterfrom
dev/mazi/focustheming

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #23242

PR Type:

🐞 Bugfix

What changed? 🚀

DependencyProperty.GetDefaultValue resolved the default values for FocusVisualPrimaryBrush / FocusVisualSecondaryBrush via ResourceResolver.TryStaticRetrieval("SystemControlFocusVisual…Brush", null, …). The null context made the lookup pick whichever theme was currently active at the application level, so an element inside a subtree with an explicit RequestedTheme different from Application.Current.RequestedTheme would 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's CDependencyProperty::GetDefaultFocusVisualBrush which resolves against targetObject->GetTheme() (MUX reference: microsoft-ui-xaml2/src/dxaml/xcp/core/core/elements/DependencyProperty.cpp, lines 131-150 and 309-345).

GetEffectiveThemeKey mirrors FrameworkElement.ActualTheme's fallback chain (element _theme → Application.Current.ActualElementTheme → Light).

PR Checklist ✅

Tests added

Five new [RequiresFullWindow] runtime tests in Given_FrameworkElement_FocusVisuals cover:

  • Element with RequestedTheme=Light while app is Dark → primary brush is Light (#E4000000).
  • Element with RequestedTheme=Dark while app is Light → primary brush is Dark (#FFFFFFFF).
  • Same coverage for the secondary brush (#B3FFFFFF Light / #B3000000 Dark).
  • Child inheriting the parent's RequestedTheme=Light while app is Dark → primary brush is Light.

All 10 tests in the class pass on Skia Desktop (5 existing + 5 new).

…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]>
Copilot AI review requested due to automatic review settings May 11, 2026 12:45

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

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.GetDefaultValue to 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.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund merged commit 78f92a7 into master May 17, 2026
49 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/focustheming branch May 17, 2026 15:34
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.

Focus visual ignores element-level RequestedTheme, follows app/system theme instead

4 participants