Class TreeViewNode
A ready-made data item for a TreeView: a header, child nodes, and per-node expansion and selectability. Lets a static tree be written directly in markup.
[ContentProperty("Children")]
public class TreeViewNode : INotifyPropertyChanged
- Inheritance
-
TreeViewNode
- Implements
- Inherited Members
- Extension Methods
Remarks
Children is the content property, so nested <TreeViewNode> elements need no wrapper:
<TreeView>
<TreeViewNode Header="Basics" IsSelectable="False" IsExpanded="True">
<TreeViewNode Header="Controls"/>
</TreeViewNode>
</TreeView>
A TreeView reads IsExpanded as the node's expansion state and keeps it in step both ways, and treats IsSelectable as the node's selectability unless IsItemSelectable is set. Without an item template, a row shows ToString().
Constructors
TreeViewNode()
Initializes a new instance of the TreeViewNode class with no header.
public TreeViewNode()
TreeViewNode(object?)
Initializes a new instance of the TreeViewNode class.
public TreeViewNode(object? header)
Parameters
headerobjectThe header to show.
Properties
Children
Gets the child nodes. A TreeView follows changes to this collection while the node is visible.
public ObservableCollection<TreeViewNode> Children { get; }
Property Value
Header
Gets or sets what the node's row shows.
public object? Header { get; set; }
Property Value
IsExpanded
Gets or sets a value indicating whether the node shows its children. Defaults to false.
public bool IsExpanded { get; set; }
Property Value
IsSelectable
Gets or sets a value indicating whether the node can be selected. Defaults to true. Tapping a non-selectable node with children opens or closes it instead.
public bool IsSelectable { get; set; }
Property Value
Tag
Gets or sets any data the application wants to attach to the node.
public object? Tag { get; set; }
Property Value
Methods
ToString()
Returns the text of Header.
public override string ToString()
Returns
Events
PropertyChanged
Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged