Skip to content

TreeView class

A hierarchical tree view control with expand/collapse functionality.

Guide: C# Markup reference: Treeview

public sealed class TreeView : Control, IMultiSelector, ISubtreeInvalidationHost
name description
TreeView() Initializes a new instance of the TreeView class.
ExpandTrigger { get; set; } Gets or sets which user interactions toggle node expansion.
HorizontalScroll { get; set; } Gets or sets the horizontal scroll mode, Auto by default, so items wider than the viewport scroll horizontally.
Indent { get; set; } Gets or sets the horizontal indentation per tree level.
ItemHeight { get; set; } Gets or sets the height of each tree node row.
ItemPadding { get; set; } Gets or sets the padding around each node’s text.
ItemsSource { get; set; } Gets or sets the items source: the hierarchical view that supplies the visible rows.
ItemTemplate { get; set; } Gets or sets the node template; unset, the default template is used.
SelectedIndices { get; } Gets the selected visible-row indices in ascending order.
SelectedItem { get; set; } Gets or sets the selected item as an object: the SelectedNode for TreeViewNode -based items, or the typed item for a TreeItemsView.
SelectedItems { get; } Gets the selected items in ascending visible-row order (read-only, bindable).
SelectedNode { get; set; } Gets or sets the currently selected tree node.
SelectionMode { get; set; } Gets or sets the selection mode; multi-selection needs an items source that supports it (e.g. TreeItemsView), otherwise the mode stays Single.
event Collapsing Occurs immediately before an item is collapsed.
event Expanding Occurs immediately before an item is expanded.
event SelectedIndicesChanged Occurs when the set of selected rows changes (multi-select).
event SelectedNodeChanged Occurs when the selected node changes.
event SelectionChanged Occurs when the selected item changes.
ClearSelection() Clears the entire selection.
Collapse(…) Collapses the specified node to hide its children.
Expand(…) Expands the specified node to show its children.
IsExpanded(…) Checks whether the specified node is expanded.
IsSelected(…) Returns whether the item at the given visible-row index is selected.
ScrollIntoView(…) Scrolls the specified visible item index into view.
ScrollIntoViewSelected() Scrolls the selected node into view.
SelectAll() Selects every visible item (multi-selection modes only; no-op otherwise).
SelectRange(…) Selects the inclusive visible-row range [start, end], replacing the selection (multi only).
Toggle(…) Toggles the expansion state of the specified node.
TryGetContainer(…) Gets the container currently showing the visible row at index, counted over the expanded nodes. False when that row is not realized, which is the normal state of one scrolled out of view.
TryGetItemIndexAt(…) Attempts to find the item (row) index at the specified position in this control’s coordinates. (2 methods)
static readonly ExpandTriggerProperty
static readonly HorizontalScrollProperty
static readonly IndentProperty
static readonly ItemHeightProperty Gets or sets the height of each tree node row.
static readonly ItemPaddingProperty Gets or sets the padding around each node’s text.
static readonly SelectedItemProperty
static readonly SelectedItemsProperty
static readonly SelectedNodeProperty
static readonly SelectionModeProperty Gets or sets the selection mode. Requires a multi-selection-capable items source (e.g. TreeItemsView); otherwise stays Single. Range selection follows the flattened visible-row order. Parent/child propagation is not applied.