You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(treeview): typed data-driven TreeView<T> with per-container hosting (#447)
A node-mode WinUI TreeView stringifies TreeViewNode.Content and cannot host
a pre-built UIElement, so TreeViewNodeData.ContentElement rendered blank
rows (#447). Add a typed, data-driven TreeView<T> — the hierarchical peer of
ListView<T> — that renders each node from a data -> Element viewBuilder (the
WinUI ItemTemplate equivalent), with heterogeneous nodes handled by a switch
in the viewBuilder (the ItemTemplateSelector pattern).
Hosting mirrors the typed ListView<T>: the ItemTemplate is an empty
ContentControl shell and each node view is mounted imperatively into the
realized container via the internal TreeViewList's ContainerContentChanging
(fresh mount on realize, unmount on recycle). This keeps expand/collapse
robust under container recycling — fixing the "every other expand/collapse
blanks the first child row(s)" regression that the earlier declarative
{Binding Content} approach suffered (a recycled container retained the
element's visual parent). node.Content holds the data item; the ItemInvoked
and Expanding trampolines read T back from it.
TreeViewNodeData.ContentElement is marked [Obsolete] pointing at TreeView<T>;
the legacy path stays functional (CS0618 suppressed at internal use sites).
- Element.cs: TemplatedTreeViewElementBase (object-erased base) +
TemplatedTreeViewElement<T>; OwnPropsEqual arm.
- Dsl.cs: TreeView<T> factory overloads (explicit + IReactorKeyed).
- Reconciler: empty-shell ItemTemplate, ContainerContentChanging hosting on
the internal TreeViewList, keyed in-place node diff that reconciles only
realized containers, full-tree unmount walk.
- Samples: DataTemplateDemo section 4 migrated to a discriminated PetNode model.
- Tests: TemplatedTreeViewFixtures (TTV_) — render, heterogeneous templates,
keyed update, expand/collapse cycles, events, value-type T, unmount.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
/// — the hierarchical peer of <c>ListView<T></c> — instead. The legacy
1756
+
/// path stays functional for back-compat but renders blank under
1757
+
/// virtualization recycling.
1758
+
/// </remarks>
1759
+
[Obsolete("Use the typed UI.TreeView<T>(items, keySelector, childrenSelector, viewBuilder) overload (the hierarchical peer of ListView<T>); a pre-built Element cannot be hosted in a node-mode TreeViewNode. See issue #447.")]
1739
1760
publicElement?ContentElement{get;init;}
1740
1761
}
1741
1762
@@ -3192,6 +3213,122 @@ public override void ApplyControlSetters(object control) =>
0 commit comments