Skip to content

Fix ThemeRef PaneBackground, InteractionStates restore, author Style and key quoting on the Style path - #1636

Draft
Alexandre Zollinger Chohfi (azchohfi) wants to merge 1 commit into
mainfrom
azchohfi-themeref-stable-sdk-fixes
Draft

Alexandre Zollinger Chohfi (azchohfi) wants to merge 1 commit into
mainfrom
azchohfi-themeref-stable-sdk-fixes

Conversation

@azchohfi

Copy link
Copy Markdown
Collaborator

Summary

Lands the ThemeRef fixes from #1618 that don't need SetThemeResourceBinding, on the stable Windows App SDK, keeping Reconciler.ApplyThemeBindings' XamlReader {ThemeResource} Style. #1618 stays the later API swap. Doesn't touch ThemeRef.Resolve or ThemeResourceProbe (#1633).

  • SplitView.PaneBackground(ThemeRef) was a silent no-op. GetDependencyPropertyName and GetStyleTargetType now map it, and the descriptor entry is the Optional-backed OneWay(..., dp:), so a removed .PaneBackground(brush) is cleared. Found along the way: a loaded SplitView throws E_INVALIDARG on any Style write (even an empty Style, or ClearValue) unless the new Style is BasedOn DefaultSplitViewStyle. That already crashes on main when a ThemeRef is added to or removed from a mounted SplitView. The themed Style for a SplitView is now built on DefaultSplitViewStyle.
  • InteractionStates no longer freezes a ThemeRef Background or Foreground. The normal value is captured when a state first writes over the property, not at setup. On restore, nothing happens unless the property still holds the state's brush. A captured local brush is written back, and no local value means ClearValue, so the {ThemeResource} setter takes over again. Opacity-only states no longer touch brushes.
  • The author's Style is kept. This covers .Set(c => c.Style = s), .ApplyStyle, .AccentButton(), .SubtleButton(), .TextLink(), Title(...) and the other typography factories. The themed Style is built BasedOn it and targets the control's own WinUI type, so BasedOn is always valid.
    • On re-render the base is read back from a new attached DP, so styles don't chain.
    • Cache entries are keyed by an id stamped on the base Style through an attached DP, with a size cap.
    • Re-applying toggles through the base instead of null, so a custom Template isn't rebuilt.
    • ClearThemeBindings restores the base. Same idea as draft Add native SettingsCard and SettingsExpander (spec 065) #1531's IReactorBaseStyleHost, done generically.
  • Keys are quoted and escaped in the setter value. The rules match ThemeResourceProbe.BuildStyleXaml in Resolve ThemeRef through WinUI instead of reading theme dictionaries #1633, so this can be deduped once that lands. A key that can't be written skips only that setter and logs a DiagnosticLog.Warning.

Linked issue / spec

Part of #1618 (stable-SDK half). Related: #1633, #1531, #522.

Test plan

  • New selftests ThemeRefStyleFixtures (9 fixtures, 75 checks). Each oracle was confirmed to fail on the pre-fix Reconciler.cs/Element.cs. Targeted mutations also redden their oracle: toggling through null (template rebuilt), the loose TargetType (CheckBox not themed), and no DefaultSplitViewStyle base (the app crashes).
  • Unit tests for FormatThemeResourceReference in ReconcilerCacheKeyTests. ModifierTableIntegrityTests exempts the element-specific PaneBackground, as Bind ThemeRef properties with SetThemeResourceBinding instead of a parsed Style #1618 does.
  • dotnet test tests/Reactor.Tests: passed (16057 passed, 18 skipped).
  • dotnet test tests/Reactor.SelfTests -p:Platform=x64: passed.
  • dotnet run --project tests/Reactor.AppTests.Host -- --self-test --filter for ThemeRefStyle, Issue522, PanelBorder, ThemeBindings, InterState, Theme, SplitView, NamedStyle, AnimCombo, Interaction and Pool: all pass.
  • dotnet restore Reactor.slnx, then dotnet build Reactor.slnx --no-restore -c Release -p:SkipSignaturesGen=true with NuGetAudit=false: 0 errors. Locally the network blocks nuget.org's vulnerability feed (NU1900), and SignaturesGen's nested restore can't skip it. CI isn't affected.
  • Docs: compiled only the styling topic.

Risk / breaking changes

  • Behaviour change: a ThemeRef no longer replaces an explicit Style. It layers on top of it. This was the intended behaviour, and the old one dropped named styles.
  • An InteractionStates hover-out on a property with no local value now clears it instead of writing back a captured brush.
  • Perf: an author-based themed Style is cached per base id (capped at 256). A base Style created on every render is rebuilt with XamlReader each render once the cap is reached.

…and key quoting on the Style path

Port the #1618 ThemeRef fixes that don't need SetThemeResourceBinding, keeping the
XamlReader {ThemeResource} Style:

- SplitView.PaneBackground(ThemeRef) maps to the pane background, and the descriptor
  clears a removed brush. A loaded SplitView rejects any Style not BasedOn
  DefaultSplitViewStyle (E_INVALIDARG), so the themed Style is built on it.
- InteractionStates captures the normal brush lazily and, on restore, clears a property
  that had no local value instead of writing back a brush captured at setup.
- The themed Style is built BasedOn the control's own Style (setter, ApplyStyle, named
  styles), targeting the control's exact type, cached per stamped base id, and
  ClearThemeBindings restores the base.
- ThemeRef keys are quoted and escaped in the setter value.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

📦 Build metrics

Artifact sizes for b6d499f vs the base branch (34953e5).

Packages (compressed .nupkg)

Artifact base PR Δ
Microsoft.UI.Reactor.nupkg 2.08 MB 2.08 MB +2.51 KB (+0.12%) ⚠️
Microsoft.UI.Reactor.Advanced.nupkg 523.8 KB 523.8 KB +1 B (0.00%) ≈
Microsoft.UI.Reactor.Devtools.nupkg 287.8 KB 287.8 KB -6 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor

Artifact base PR Δ
Reactor.Analyzers.dll 422.5 KB 422.5 KB +0 B (0.00%) ≈
Reactor.dll 2.82 MB 2.83 MB +3.00 KB (+0.10%) ⚠️
Reactor.Localization.Generator.dll 16.0 KB 16.0 KB +0 B (0.00%) ≈
Reactor.Wrappers.Abstractions.dll 10.5 KB 10.5 KB +0 B (0.00%) ≈
Reactor.Wrappers.Generator.dll 164.0 KB 164.0 KB +0 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor.Advanced

Artifact base PR Δ
Reactor.Advanced.dll 1.07 MB 1.07 MB +0 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor.Devtools

Artifact base PR Δ
Microsoft.UI.Reactor.Devtools.dll 787.0 KB 787.0 KB +0 B (0.00%) ≈

✅ smaller / ⚠️ larger / ≈ within noise. Sizes come from a Release dotnet pack on the CI runner: packages are the compressed .nupkg download size, assemblies the uncompressed DLL inside it.
workflow run.

Comment on lines +8421 to +8428
catch (Exception ex)
{
Microsoft.UI.Reactor.Core.Diagnostics.DiagnosticLog.SwallowedError(
Microsoft.UI.Reactor.Core.Diagnostics.LogCategory.Theme,
"ApplyThemeBindings",
ex);
return;
}
Comment on lines +8437 to +8443
catch (Exception ex)
{
Microsoft.UI.Reactor.Core.Diagnostics.DiagnosticLog.SwallowedError(
Microsoft.UI.Reactor.Core.Diagnostics.LogCategory.Theme,
"ApplyThemeBindings",
ex);
}
Comment on lines +8538 to +8541
catch (Exception)
{
return null;
}
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Merged coverage

Coverage for b6d499f vs the base branch (34953e5) — unit + selftest merged.

Metric base PR Δ
Line 88.79% 88.77% -0.02 pp ≈
Branch 46.08% (18281/39669) 46.02% (18290/39743) -0.06 pp ≈

No coverage change beyond the noise floor. ✅

✅ higher / ⚠️ lower / ≈ within noise. Δ is in percentage points; coverage is unit + selftest merged (Debug x64) on the CI runner. Cobertura reports attached to the workflow run as artifacts.

This branch has not been deployed

No deployments
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.

1 participant