Repository navigation
fix(xaml-reader): set properties on FrameworkTemplate (e.g. ControlTemplate.TargetType) - #23200
Conversation
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]>
There was a problem hiding this comment.
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.LoadObjectto iterate template sibling members (excluding unknown content and_Initialization) and apply them viaProcessNamedMember. - Add runtime tests validating
ControlTemplate.TargetTypeis set when loaded standalone and when nested inside aStylesetter.
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.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23200/wasm-skia-net9/index.html |
|
|
GitHub Issue: closes #17434
PR Type:
🐞 Bugfix
What changed? 🚀
XamlReader.Loadnow sets XAML-declared properties onFrameworkTemplatesubclasses, matching WinUI and the compiled XAML path.Before this fix, the
FrameworkTemplatebranch inXamlObjectBuilder.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 iteratedcontrol.Membersto assign sibling members. The most visible casualty wasControlTemplate.TargetType, which stayednullafter a runtime parse, even though every other branch in the sameLoadObjectmethod (MarkupExtension,ResourceDictionary, generic fallthrough) already iterates members.The fix mirrors the
ResourceDictionarybranch pattern: after creating the template instance and applying contextual properties, iteratecontrol.Members(excluding the unknown-content and_Initializationdirective) and callProcessNamedMemberfor each. The existing reflection-basedGetMemberPropertypath handlesControlTemplate.TargetType(a plainType?CLR property) without any new conversion logic;DataTemplateandItemsPanelTemplatehave 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_UNOgate so they also run against native WinUI:When_ControlTemplate_TargetType— standalone<ControlTemplate TargetType="ContentControl">asserts the parsed template'sTargetType.When_ControlTemplate_TargetType_Nested_In_Style—<Style>containing aSetter 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 fullGiven_XamlReaderclass (52 tests) continues to pass on Skia Desktop — no regressions.PR Checklist ✅
Screenshots Compare Test Runresults.