Skip to content

fix(xaml-reader): set properties on FrameworkTemplate (e.g. ControlTemplate.TargetType) - #23200

Merged
MartinZikmund merged 1 commit into
masterfrom
dev/mazi/xamlreadertempl
May 5, 2026
Merged

MartinZikmund merged 1 commit into
masterfrom
dev/mazi/xamlreadertempl

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #17434

PR Type:

🐞 Bugfix

What changed? 🚀

XamlReader.Load now sets XAML-declared properties on FrameworkTemplate subclasses, matching WinUI and the compiled XAML path.

Before this fix, the FrameworkTemplate branch in XamlObjectBuilder.LoadObject (src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs) only consumed the inner unknown-content node (used to build the template factory) and returned immediately — it never iterated control.Members to assign sibling members. The most visible casualty was ControlTemplate.TargetType, which stayed null after a runtime parse, even though every other branch in the same LoadObject method (MarkupExtension, ResourceDictionary, generic fallthrough) already iterates members.

The fix mirrors the ResourceDictionary branch pattern: after creating the template instance and applying contextual properties, iterate control.Members (excluding the unknown-content and _Initialization directive) and call ProcessNamedMember for each. The existing reflection-based GetMemberProperty path handles ControlTemplate.TargetType (a plain Type? CLR property) without any new conversion logic; DataTemplate and ItemsPanelTemplate have no extra XAML-settable properties so the loop is a no-op for them, but they remain compatible if more properties are added later.

Two parity runtime tests were added under Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Markup.Given_XamlReader_FrameworkTemplate, with no #if HAS_UNO gate so they also run against native WinUI:

  • When_ControlTemplate_TargetType — standalone <ControlTemplate TargetType="ContentControl"> asserts the parsed template's TargetType.
  • When_ControlTemplate_TargetType_Nested_In_Style — <Style> containing a Setter Property="Template" whose value is a <ControlTemplate TargetType="…">, exercising the real-world style/setter path.

Both tests pass on WinUI native (/winui-runtime-tests) before and after the fix, fail on Uno before the fix, and pass on Uno after the fix. The full Given_XamlReader class (52 tests) continues to pass on Skia Desktop — no regressions.

PR Checklist ✅

XamlReader.Load now iterates members on FrameworkTemplate subclasses
(e.g. ControlTemplate.TargetType), matching WinUI and the compiled XAML
path. Previously the FrameworkTemplate branch in
XamlObjectBuilder.LoadObject only consumed the inner content node and
silently dropped sibling members.

Fixes #17434

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 5, 2026 11:44

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 a behavioral gap in the runtime XAML reader so that FrameworkTemplate subclasses (notably ControlTemplate) get their XAML-declared properties applied during XamlReader.Load, aligning the runtime parsing path with WinUI behavior and the compiled XAML path.

Changes:

  • Update XamlObjectBuilder.LoadObject to iterate template sibling members (excluding unknown content and _Initialization) and apply them via ProcessNamedMember.
  • Add runtime tests validating ControlTemplate.TargetType is set when loaded standalone and when nested inside a Style setter.

Process note: the PR description footer currently uses closes #17434; the repo guidelines require using a fully-qualified issue URL in the Fixes/Closes/Related footer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs Apply declared properties on FrameworkTemplate instances by processing relevant members after template creation.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Markup/Given_XamlReader_FrameworkTemplate.cs Adds runtime coverage for ControlTemplate.TargetType assignment in common XamlReader.Load scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 210848 has failed on Uno.UI - CI.

@MartinZikmund
MartinZikmund merged commit a5ceff4 into master May 5, 2026
49 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/xamlreadertempl branch May 5, 2026 16:04
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.

XamlReader doesn't set properties (for example TargetType) on FrameworkTemplates

4 participants