Repository navigation
fix(theming): focused NumberBox/ComboBox text is black in dark theme - #24091
morning4coffe-dev merged 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a Skia dark-theme readability regression where focused NumberBox and editable ComboBox text could render black due to theme-boundary behavior and VisualState setter {ThemeResource} resolution.
Changes:
- Adjusts theme-foreground “freeze” logic at
FrameworkElementtheme boundaries to avoid freezing a theme default over an explicitly-setForeground. - Resolves
{ThemeResource}values applied via VisualState setters using the ambient theme outside a state-appliedRequestedThemeboundary (improving WinUI parity). - Adds Skia runtime tests to validate focused text input remains light in dark theme for
NumberBoxand editableComboBox.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/ResourceResolver.cs | Uses the VisualState-setter ambient theme (when applicable) to scope theme resource resolution. |
| src/Uno.UI/UI/Xaml/FrameworkElement.Theming.cs | Fixes foreground freeze behavior at theme boundaries when Foreground is explicitly set. |
| src/Uno.UI/UI/Xaml/DependencyObjectStore.Theming.cs | Introduces ambient theme selection for VisualState setter {ThemeResource} resolution and applies it at key resolution sites. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_ElementTheme.cs | Adds Skia-focused regression tests for dark-theme text input foreground in NumberBox and editable ComboBox. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24091/wasm-skia-net9/index.html |
|
|
|
Reviewed this against the WinUI C++ sources and against a native WinUI oracle app, and ran an ablation of the two hunks on Skia Desktop. The diagnosis is right and the fix works on the tested path — but I think there's one defect worth fixing before merge, plus a couple of smaller notes. The core premise checks outI built a small WinUI 3 app (WinAppSDK 2.1.3) to measure what WinUI actually resolves, since the claim ("the boundary applies but the
So WinUI does apply the Blocking: the ComboBox half is a no-op when the app never switches theme
And
So on an app that simply starts in dark — which is what #24021 reports — the ComboBox half of this fix does nothing. The tests here can't see it because Suggested fix: when the parent's stored theme is Caveat on my own evidence: I verified each link of that chain individually (the probe above, plus reading the fallback). I did not stage a full cold-start dark app end-to-end — the runtime-test harness pins its frame to Light, which is exactly what the new test has to work around. The two defects aren't one-per-controlAblation on Skia Desktop, each configuration built and run:
The freeze defect hits both controls (it corrupts the child display block, not Smaller notesThe assertions can pass for the wrong reason.
Platform condition. On the precedence gate
That's a follow-up, not a merge blocker — this PR strictly narrows a pre-existing divergence rather than widening it. FWIW I've since pushed a setter-side port on |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24091/wasm-skia-net9/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24091/wasm-skia-net9/index.html |
|
Thanks @MartinZikmund — great catch on the blocker, and the ablation was spot on. All addressed:
Agreed on the precedence gate — happy to delete it once #23491 lands. |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
The foreground freeze now follows WinUI's explicit/local/style/animated-value bailout, instead of retaining a competing theme-default brush for descendants. Resolving the state setter outside the RequestedTheme boundary introduced by that same state is scoped to animation-precedence boundaries, preserving authored element-theme behavior. The focused-state background assertion is a useful positive control beyond merely observing light text. Source approval only; the older DependencyObjectStore-based head still needs its base conflicts integrated.
a3c256b to
ca5c81f
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core theming/resource-resolution behavior with broad potential impact beyond the targeted controls and warrants final human validation.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24091/wasm-skia-net9/index.html |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Rechecked the conflict-resolution follow-up against the previously approved patch. The substantive adaptation is to master's DependencyObjectStore-to-DependencyObject consolidation: the parent walk-theme and established-theme checks now use the parent DependencyObject directly, and ResourceResolver calls the helper on the target directly. ActualInstance is now the object itself, so these preserve the prior ambient-theme fallback and foreground-precedence behavior. The focused NumberBox/ComboBox regression cases are unchanged. Approval renewed for this head.
|
The build 232951 found UI Test snapshots differences: Details
|
|
|
|
@Mergifyio backport servicing/6.8 release/stable/6.7 |
✅ Backports have been createdDetails
|
…r-24091 fix(theming): focused NumberBox/ComboBox text is black in dark theme (backport #24091)
…6.7/pr-24091 fix(theming): focused NumberBox/ComboBox text is black in dark theme (backport #24091)
…t-6.8 fix(theming): Keep focused NumberBox/ComboBox text readable in dark theme (6.x port of #24091)
…orm#25764), 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, build 241913). A 6.x port of unoplatform#24091 needs its own change, validated by CI. This reverts commit 3001f20, reversing changes made to eb72d28. Related to unoplatform#24021 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings back the backport of unoplatform#24091 exactly as it was on master: keep focused NumberBox / editable ComboBox text readable in dark theme. It was first backported in unoplatform#25764 and reverted by unoplatform#25787 because it did not build. This commit alone still does not build on 6.x: on master DependencyObject is a class, on 6.x the theming state lives on DependencyObjectStore. The next commit adapts it. Related to unoplatform#24021 Co-authored-by: Andres Pineda <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
Brings back the backport of unoplatform#24091 exactly as it was on master: keep focused NumberBox / editable ComboBox text readable in dark theme. It was first backported in unoplatform#25764 and reverted by unoplatform#25787 because it did not build. This commit alone still does not build on 6.x: on master DependencyObject is a class, on 6.x the theming state lives on DependencyObjectStore. The next commit adapts it. Related to unoplatform#24021 Co-authored-by: Andres Pineda <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 33eb367)
GitHub Issue: closes #24021
PR Type:
🐞 Bugfix
What changed? 🚀
On Skia, text typed into a focused
NumberBoxor editableComboBoxrendered black while the app was in dark theme, making it nearly unreadable.Both templates carry (verbatim from current WinUI) a
Focusedvisual state that setsContentElement.RequestedTheme="Light"on the innerTextBox. 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 editableComboBox.NumberBoxapplies its focused foreground throughObjectAnimationUsingKeyFrames, whose keyframe value resolves under its own templated-parent theme and was already correct — so the freeze fix alone makesNumberBoxpass, whileComboBoxneeds 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-themeDefaultTextForegroundThemeBrush(black) onto the boundary element and its children, even when that element already had aForegroundset 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 theSetValuewhile still recording_themeForeground/_isForegroundFrozen, which then blocked the explicit value from cascading to children through DP inheritance. On Skia the typed text is theTextBoxViewDisplayBlock, which inheritsForegroundfromContentElement— 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_themeForegroundbrush an earlier walk may have left (Uno keeps it in a separate field, while WinUI shares the localForegroundslot, so only Uno can leak it to children) and leaves_isForegroundFrozenuntouched — WinUI's bail is a pure cleanup jump that writes no freeze state, so the boundary keeps blocking cross-boundaryForegroundinheritance.2. VisualState setter
{ThemeResource}re-resolved under its target's own theme (editable ComboBox only)A
{ThemeResource}inside aVisualStateSetteris registered on the target element in Uno. When the same state also appliedRequestedTheme="Light"to that target, the resulting theme walk re-resolvedTextControlForegroundFocusedunder Light and produced a black brush.In WinUI the resource reference lives on the
SetterDO, which sits in the template'sVisualStateGroups— outside the target's subtree — so it never resolves under the target'sRequestedTheme.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 (RequestedThemeatAnimationsprecedence); a XAML-authoredRequestedThemekeeps 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 isUNO_HAS_ENHANCED_LIFECYCLE-only; native targets keep their existing behavior.Behavior change
Theme resolution changes in two observable ways, both toward WinUI parity:
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.{ThemeResource}in aVisualStateSetternow resolves under the ambient theme rather than the target's ownRequestedTheme, only when thatRequestedThemewas 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
SamplesApp.Skia.Generic(Release, net10.0) — 0 warnings, 0 errors.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 unguardedApplyVisualStateSetterpath there. Native runtime tests are excluded from PR CI by design, so it first executes there on the post-mergemasterbranch build;Uno.UI.RuntimeTests.Wasm(and the changedUno.UIsources under__WASM__) were compile-validated locally.BorderElement.Backgroundis the darkTextControlBackgroundFocusedvalue (#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".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
PlatformConditionalready excludes them). Native WASM has direct coverage through theContentElementtest above, but native runtime tests only run on branch builds — first execution is master's post-merge build;Screenshots Compare Test Runresults remain the broader check.PR Checklist ✅
Screenshots Compare Test Runresults. — to be validated once the CI run completes