Skip to content

TreeView markup reference

TreeView nodes, expansion, and selection.

Receiver: TreeView.

Method Sets Summary
ClearContainer(PrepareContainerHandler<ItemContainer, T> clear) Releases what PrepareContainer attached outside the template context, before the container takes another item. Most hooks need no counterpart: context subscriptions and container properties are undone for you.
Collapse(TreeViewNode node) Collapses a node.
Expand(TreeViewNode node) Expands a node.
ExpandTrigger(TreeViewExpandTrigger value) ExpandTrigger Sets which user interactions toggle node expansion.
HorizontalScroll(ScrollMode value) HorizontalScroll Sets the horizontal scroll mode, Auto by default, so items wider than the viewport scroll horizontally.
Indent(double value) Indent Sets the horizontal indentation per tree level.
ItemHeight(double value) ItemHeight Sets the height of each tree node row.
ItemPadding(Thickness value) ItemPadding Sets the padding around each node’s text.
ItemTemplate(Func<TemplateContext, FrameworkElement> build, Action<FrameworkElement, TItem, int, TemplateContext> bind, Action<FrameworkElement, TItem, int, TemplateContext> unbind = null) Sets the node template using delegate-based templating.
ItemTemplate(Func<TemplateContext, TElement> build, Action<TElement, TItem, int, TemplateContext> bind, Action<TElement, TItem, int, TemplateContext> unbind = null) Sets the node template; the bind callback receives the root the build callback returned.
ItemTemplate(Func<TemplateContext, TElement> build, Action<TElement, TItem> bind) Sets the node template from a root element and a bind callback that needs only the item.
ItemTemplate(IDataTemplate template) ItemTemplate Sets the node template.
Items(IReadOnlyList<T> roots, Func<T, IReadOnlyList<T>> childrenSelector, Func<T, string> textSelector = null, Func<T, object> keySelector = null, Func<T, bool> isExpandableSelector = null) Sets a hierarchical items source using a children selector.
ItemsSource(IReadOnlyList<TreeViewNode> items) ItemsSource Sets the items source.
ItemsSource(ITreeItemsView itemsView) ItemsSource Sets the items source directly from an ITreeItemsView.
OnCollapsing(Action<TreeViewExpansionEventArgs> handler) event Collapsing Adds a handler that runs immediately before a tree item is collapsed.
OnExpanding(Action<TreeViewExpansionEventArgs> handler) event Expanding Adds a handler that runs immediately before a tree item is expanded.
OnSelectedIndicesChanged(Action handler) event SelectedIndicesChanged Subscribes handler to SelectedIndicesChanged. Occurs when the set of selected rows changes (multi-select).
OnSelectedNodeChanged(Action<TreeViewNode> handler) event SelectedNodeChanged Adds a selected node changed event handler.
OnSelectionChanged(Action<object> handler) event SelectionChanged Adds a selection changed event handler.
PrepareContainer(PrepareContainerHandler<ItemContainer, T> prepare) Configures the container placed around each row once its content is bound, so behavior can be attached to the whole row, indent and expander included, instead of to the template.
SelectedItem(object value) SelectedItem Sets the selected item as an object: the SelectedNode for TreeViewNode -based items, or the typed item for a TreeItemsView.
SelectedNode(TreeViewNode value) SelectedNode Sets the currently selected tree node.
SelectionMode(ItemsSelectionMode value) SelectionMode Sets the selection mode; multi-selection needs an items source that supports it (e.g. TreeItemsView), otherwise the mode stays Single.
Toggle(TreeViewNode node) Toggles a node expansion state.