Skip to content

fix(theming): focused NumberBox/ComboBox text is black in dark theme (backport #24091) - #25765

Merged
agneszitte merged 7 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-24091
Oct 27, 2026
Merged

agneszitte merged 7 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-24091

Conversation

@mergify

@mergify mergify Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24021

PR Type:

🐞 Bugfix

What changed? 🚀

On Skia, text typed into a focused NumberBox or editable ComboBox rendered black while the app was in dark theme, making it nearly unreadable.

Both templates carry (verbatim from current WinUI) a Focused visual state that sets ContentElement.RequestedTheme="Light" on the inner TextBox. In WinUI that is harmless; in Uno it exposed two distinct defects — though not one per control: the foreground-freeze defect affects both controls, while the setter-resolution defect affects only the editable ComboBox. NumberBox applies its focused foreground through ObjectAnimationUsingKeyFrames, whose keyframe value resolves under its own templated-parent theme and was already correct — so the freeze fix alone makes NumberBox pass, while ComboBox needs both fixes (confirmed by ablation of the hunks; thanks @MartinZikmund for measuring this).

1. Foreground freeze overrode an explicitly-set Foreground (both controls)

FrameworkElement.NotifyThemeChangedForInheritedProperties(freeze: true) froze the Light-theme DefaultTextForegroundThemeBrush (black) onto the boundary element and its children, even when that element already had a Foreground set locally, by style, or by animation.

WinUI (framework.cpp, NotifyThemeChangedForInheritedProperties) skips the entire freeze in that case — "there is nothing to do, because that value will be used". Uno only skipped the SetValue while still recording _themeForeground / _isForegroundFrozen, which then blocked the explicit value from cascading to children through DP inheritance. On Skia the typed text is the TextBoxView DisplayBlock, which inherits Foreground from ContentElement — so it picked up the frozen black brush. This corrupts the child display block regardless of how the focused foreground was applied, which is why it hits both controls.

Fix: early-return when the foreground precedence is above Inheritance. The bail clears only the stored _themeForeground brush an earlier walk may have left (Uno keeps it in a separate field, while WinUI shares the local Foreground slot, so only Uno can leak it to children) and leaves _isForegroundFrozen untouched — WinUI's bail is a pure cleanup jump that writes no freeze state, so the boundary keeps blocking cross-boundary Foreground inheritance.

2. VisualState setter {ThemeResource} re-resolved under its target's own theme (editable ComboBox only)

A {ThemeResource} inside a VisualState Setter is registered on the target element in Uno. When the same state also applied RequestedTheme="Light" to that target, the resulting theme walk re-resolved TextControlForegroundFocused under Light and produced a black brush.

In WinUI the resource reference lives on the Setter DO, which sits in the template's VisualStateGroups — outside the target's subtree — so it never resolves under the target's RequestedTheme.

Fix: DependencyObjectStore.GetVisualStateSetterResolutionTheme() returns the ambient theme surrounding the target, applied at the three resolution sites (UpdateThemeReference, InnerUpdateResourceBindingsUnsafe, ResourceResolver.ApplyVisualStateSetter). It is deliberately scoped to boundaries applied by the state itself (RequestedTheme at Animations precedence); a XAML-authored RequestedTheme keeps Uno's existing element-level theming semantics for setter targets.

Mid-walk, an ancestor's persisted theme is stale (it is persisted only after its subtree completes), so the ambient is read from the parent's in-flight walk theme when the parent is still processing a theme walk.

When the parent has no established per-object theme — the state of every element in an app that never switches theme at runtime, since only a theme walk persists per-object themes — the ambient now falls back to the application base theme (FrameworkTheming.GetBaseTheme()). ResolveOwnerTheme's owner-less fallback instead reads the requested-theme-for-subtree slot, which mid-boundary already carries the very Light theme being escaped, silently turning the escape into a no-op — so the fix did nothing in exactly the cold-start-dark scenario #24021 reports. Caught in review by @MartinZikmund. The fallback is UNO_HAS_ENHANCED_LIFECYCLE-only; native targets keep their existing behavior.

Behavior change

Theme resolution changes in two observable ways, both toward WinUI parity:

  • An element with an explicitly-set Foreground (local / style / animation) no longer has the theme's default foreground frozen over it — and no longer propagates that frozen default to its children — when it acts as a theme boundary.
  • A {ThemeResource} in a VisualState Setter now resolves under the ambient theme rather than the target's own RequestedTheme, only when that RequestedTheme was applied by a visual state.

Existing app code that (intentionally or not) relied on the frozen-default behaviour could see a different foreground on such elements. No public API changed.

Validation

  • Build: SamplesApp.Skia.Generic (Release, net10.0) — 0 warnings, 0 errors.
  • Runtime tests (Skia Desktop): Given_ElementTheme — 115 tests, 114 passed. The regression tests fail before their respective fixes and pass after:
    • When_NumberBox_Focused_In_Dark_Theme_Text_Is_Light (freeze fix)
    • When_Editable_ComboBox_Focused_In_Dark_Theme_Text_Is_Light (freeze + setter-resolution fixes)
    • When_Editable_ComboBox_Focused_In_Dark_Theme_Without_Theme_Walk_Text_Is_Light (base-theme fallback) — stages the never-theme-switched cold start (the exact [Skia] the input foreground of NumberBox or ComboBox is black at dark theme #24021 scenario) by clearing the per-object themes the harness's theme switch persists; on a build without the fallback it fails with the focused text at #E4000000 (black).
    • When_Editable_ComboBox_Focused_In_Dark_Theme_ContentElement_Foreground_Is_Light — platform-agnostic variant asserting the setter's direct target (ContentElement.Foreground, no Skia display-block dependency); it is also enabled for native WASM to cover the unguarded ApplyVisualStateSetter path there. Native runtime tests are excluded from PR CI by design, so it first executes there on the post-merge master branch build; Uno.UI.RuntimeTests.Wasm (and the changed Uno.UI sources under __WASM__) were compile-validated locally.
    • Every test carries a positive control asserting BorderElement.Background is the dark TextControlBackgroundFocused value (#B31E1E1E), proving the Focused state actually ran and resolved Dark — the Dark dictionary aliases all text-control foregrounds to the same light brush, so the foreground assert alone can't distinguish "resolved correctly" from "state never applied".
    • The single failure, When_Flyout_Closed_Target_Does_Not_Hold_Flyout, is a pre-existing GC/leak-sensitive test that fails identically on the unmodified branch — unrelated to this change.

Not yet measured

  • Native Android/iOS were not exercised beyond compilation (the class-level PlatformCondition already excludes them). Native WASM has direct coverage through the ContentElement test above, but native runtime tests only run on branch builds — first execution is master's post-merge build; Screenshots Compare Test Run results remain the broader check.
  • No performance measurement was taken. The added work is an extra precedence check on the setter path and an early return on the freeze path, so no regression is expected, but it has not been benchmarked.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable)
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — no documented behaviour changes; the fix aligns with existing WinUI-documented semantics
  • 🖼️ Validated PR Screenshots Compare Test Run results. — to be validated once the CI run completes
  • ❗ Contains NO breaking changes — see the Behavior change section above; theme resolution is observably different in two cases, both toward WinUI parity
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

This is an automatic backport of pull request #24091 done by [Mergify](https://mergify.com).

@agneszitte
agneszitte merged commit eaefbb6 into release/stable/6.7 Oct 27, 2026
10 of 17 checks passed
@agneszitte
agneszitte deleted the mergify/bp/release/stable/6.7/pr-24091 branch October 27, 2026 23:27
ramezgerges pushed a commit to ramezgerges/uno that referenced this pull request Nov 2, 2026
…orm#25765), it doesn't build on 6.x

The cherry-picked fix adds members to the DependencyObject class (GetTheme,
WalkTheme, IsProcessingThemeWalk, GetVisualStateSetterResolutionTheme). On
6.x DependencyObject is still an interface, so Uno.UI no longer compiles
(CS1061/CS0117 in ResourceResolver.cs and DependencyObjectStore.Theming.cs,
the same errors as 6.8's build 241913 (same code)). A 6.x port of unoplatform#24091 needs its own change, validated by CI.

This reverts commit eaefbb6, reversing
changes made to 8fa10d7.

Related to unoplatform#24021

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants