Skip to content

Fix themed foreground on RichTextBlock - #1655

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 4 commits into
microsoft:mainfrom
PaperHammer:fix/issue1002-richtextblock-theme-foreground
Nov 23, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 4 commits into
microsoft:mainfrom
PaperHammer:fix/issue1002-richtextblock-theme-foreground

Conversation

@PaperHammer

Copy link
Copy Markdown
Contributor

Summary

RichTextBlock("Hello").Foreground(Theme.PrimaryText) compiled, but the reconciler skipped the foreground theme binding. This PR adds RichTextBlock to the existing {ThemeResource} foreground path so its default text brush follows the control's effective theme.

  • Make REACTOR_MOD_003 use the receiver list for the resolved overload. The analyzer accepts themed foreground on RichTextBlock and still flags unsupported calls through the generic brush overload.
  • Remove the StepCard.cs diagnostic exemption and update the guides, agent-kit documentation, and changelog.

Linked issue / spec

Fixes #1002.

Test plan

  • Restored and built the full solution in Release. The build completed with zero errors and MSB3277 assembly version warnings.
  • Passed all 16 ThemeRefStyle WinUI selftests. The new regression fixture failed three brush assertions before the fix and passed after it. It covers initial binding, a live theme change, switching between an explicit brush and a theme token, and removing the binding on the same control.
  • Passed all 228 targeted analyzer and agent-kit documentation tests.
  • Built DemoScriptTool in Debug x64 with the StepCard.cs exemption removed.
  • Regenerated the Text and Media and Analyzer Architecture guides. Link and API reference checks passed.

The full Debug unit suite reported 16,238 passed, 18 skipped, and 2 failures in the CLI's CS1503 suggestion tests under the machine's default locale. Both failing tests passed when rerun with DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1.

Risk / breaking changes

Existing calls keep the same public signatures and overload resolution. The visible behavior change is that a theme token now sets the default foreground on RichTextBlock. The existing string and brush overloads continue to use the control descriptor.

@PaperHammer

Copy link
Copy Markdown
Contributor Author

Could we take a look at the current approach together? The existing Foreground<T>(ThemeRef) already accepts the theme token and preserves RichTextBlockElement as the return type. A dedicated overload that forwards to the same theme-binding implementation would still go through the same runtime receiver check, so it would also need that check to support RichTextBlock.

The patch extends that check so the existing call can use WinUI’s {ThemeResource} handling. The WinUI regression test confirms that the brush is applied on mount, updates when the effective theme changes, and clears when the binding is removed from the same control.

I’d appreciate your thoughts on whether this approach fits the issue. Existing generic overload · Runtime receiver check

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.

🟢 Approval recommended

No active review issues block approval of the RichTextBlock foreground theming change.

No open issues 🎉

What changed in this PR

Fixes #1002 by routing RichTextBlock foreground theme tokens through Reactor’s existing theme-resource binding path, without changing public signatures or overload resolution.

Changes:

  • Enables themed foreground on RichTextBlock and makes REACTOR_MOD_003 distinguish themed and generic brush overloads.
  • Adds regression coverage for theme changes, brush transitions, binding removal, and analyzer receiver checks.
  • Removes the StepCard.cs diagnostic exemption and updates documentation and the changelog.
File Description
tests/​Reactor.Tests/​AnalyzerTests/​NoOpModifierAnalyzerTests.cs Tests supported themed calls and unsupported generic calls.
tests/​Reactor.Tests/​AnalyzerTests/​ModifierTableIntegrityTests.cs Validates separate theme receiver lists against reconciler behavior.
tests/​Reactor.Tests/​AnalyzerTests/​AgentKitSnippetWalker.cs Clarifies comments about syntax-only overload checking.
tests/​Reactor.AppTests.Host/​SelfTest/​SelfTestFixtureRegistry.cs Registers the new foreground regression fixture.
tests/​Reactor.AppTests.Host/​SelfTest/​Fixtures/​ThemeRefStyleFixtures.cs Covers live theming, brush transitions, and binding removal.
src/​Reactor/​Elements/​ElementExtensions.cs Documents supported themed foreground receivers.
src/​Reactor/​Core/​Reconciler.cs Enables foreground theme bindings for RichTextBlock.
src/​Reactor.Analyzers/​NoOpModifierAnalyzer.cs Selects the receiver list for the resolved overload.
src/​Reactor.Analyzers/​ModifierTable.cs Declares the themed foreground receiver list.
src/​Reactor.Analyzers/​AnalyzerReleases.Unshipped.md Updates the diagnostic description.
samples/​.editorconfig Removes the StepCard.cs exemption and refreshes explanatory comments.
plugins/​reactor/​skills/​reactor-build-and-check/​SKILL.md Documents overload-specific foreground support.
docs/​guide/​text-and-media.md Adds generated guidance for themed rich text.
docs/​guide/​analyzer-architecture.md Updates generated analyzer guidance.
docs/​_pipeline/​templates/​text-and-media.md.dt Adds themed rich-text guidance to the source template.
docs/​_pipeline/​templates/​analyzer-architecture.md.dt Documents overload-specific receiver checks in the source template.
CHANGELOG.md Records the foreground theming fix.

Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks right to me. The themed Style path, pooling cleanup and the brush to theme to none transitions all check out, and the selftest would go red if the Reconciler line were reverted. A few small things inline, none blocking.

Comment thread src/Reactor/Core/Reconciler.cs Resolved
Check explicit theme gates against ApplyModifiers and verify the shipped ThemeRef receiver lists.
@PaperHammer

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I kept the analyzer-to-runtime equality check and added a superset check so an explicit theme gate must cover every receiver supported by ApplyModifiers. The agent kit now lists ThemeRef gates: separately, explains when the ordinary receiver list applies, and has a parity test against ThemeControlGate. All 229 targeted tests passed.

I’ll follow up separately on sharing the foreground dependency-property lookup across the three paths, including support for AnimatedIcon.

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.

🟢 Approval recommended

No active review issues remain for the change enabling themed foreground bindings on RichTextBlock.

No open issues 🎉

Review effort: Balanced

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both fixes look good. Merged main to fix the CHANGELOG conflict.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit dbda02a into microsoft:main Nov 23, 2026
43 checks passed
@azchohfi

Copy link
Copy Markdown
Collaborator

Filed #1674 for the shared Foreground lookup and AnimatedIcon follow-up.

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.

[Bug] RichTextBlock.Foreground has no ThemeRef overload, so .Foreground(Theme.X) is silently dropped

3 participants