Class TreeView
- Namespace
- Myra.Graphics2D.UI
- Assembly
- Myra.dll
A hierarchical tree view widget that displays nodes in an expandable/collapsible tree structure.
public class TreeView : Widget, IItemWithId, INotifyAttachedPropertyChanged, ITreeViewNode
- Inheritance
-
TreeView
- Implements
- Inherited Members
Constructors
TreeView(Stylesheet, string)
Initializes a new instance of the TreeView class with the specified stylesheet and style.
public TreeView(Stylesheet stylesheet, string styleName = "")
Parameters
stylesheetStylesheetThe stylesheet to use for applying the style.
styleNamestringThe name of the style to apply. Defaults to the default stylesheet style.
TreeView(string)
Initializes a new instance of the TreeView class with the specified style.
public TreeView(string styleName = "")
Parameters
styleNamestringThe name of the style to apply. Defaults to the default stylesheet style.
Properties
ChildNodesCount
Gets the number of top-level child nodes.
[Obsolete("Use SubNodesCount")]
public int ChildNodesCount { get; }
Property Value
SelectedNode
Gets or sets the currently selected node.
[Browsable(false)]
public TreeViewNode SelectedNode { get; set; }
Property Value
SelectionBackground
Gets or sets the brush used to draw the background of selected nodes.
public IBrush SelectionBackground { get; set; }
Property Value
SelectionHoverBackground
Gets or sets the brush used to draw the background of hovered nodes.
public IBrush SelectionHoverBackground { get; set; }
Property Value
SubNodesCount
Gets the number of child nodes directly under this tree view.
public int SubNodesCount { get; }
Property Value
TotalNodesCount
Gets the total number of nodes in the tree (including all nested nodes).
public int TotalNodesCount { get; }
Property Value
Methods
AddSubNode(Widget)
Adds a new top-level node to the tree with the specified content.
public TreeViewNode AddSubNode(Widget content)
Parameters
contentWidgetThe widget to display as the node's content.
Returns
- TreeViewNode
The newly created tree node.
ApplyStyle(WidgetStyle)
Applies the specified widget style to this tree view.
protected override void ApplyStyle(WidgetStyle style)
Parameters
styleWidgetStyleThe widget style to apply.
CopyFrom(Widget)
Copies the properties and child nodes from another tree view widget.
protected override void CopyFrom(Widget w)
Parameters
wWidgetThe source tree view widget to copy from.
ExpandPath(TreeViewNode)
Expands path to the node
public void ExpandPath(TreeViewNode node)
Parameters
nodeTreeViewNode
FindNode(Func<TreeViewNode, bool>)
Finds the first node that matches the specified predicate.
public TreeViewNode FindNode(Func<TreeViewNode, bool> predicate)
Parameters
predicateFunc<TreeViewNode, bool>A function to test each node; returns true if the node matches.
Returns
- TreeViewNode
The first matching node, or null if no nodes match.
GetNodeByAbsoluteIndex(int)
Gets a node by its absolute index (across all levels of the tree).
public TreeViewNode GetNodeByAbsoluteIndex(int index)
Parameters
indexintThe zero-based absolute index.
Returns
- TreeViewNode
The tree node at the specified absolute index.
GetSubNode(int)
Gets a top-level node by its index.
public TreeViewNode GetSubNode(int index)
Parameters
indexintThe zero-based index of the node.
Returns
- TreeViewNode
The tree node at the specified index.
InternalArrange()
Arranges the tree view and marks row information as needing update.
protected override void InternalArrange()
InternalRender(RenderContext)
Renders the tree view including selection and hover backgrounds for rows.
public override void InternalRender(RenderContext context)
Parameters
contextRenderContextThe render context used for drawing.
Iterate(Func<TreeViewNode, bool>)
Iterates through all nodes
public void Iterate(Func<TreeViewNode, bool> action)
Parameters
actionFunc<TreeViewNode, bool>Called for each node, returning false breaks iteration
OnKeyDown(Keys)
Handles keyboard input for tree navigation (Up, Down, and Enter keys).
public override void OnKeyDown(Keys k)
Parameters
kKeysThe key being pressed.
OnMouseLeft()
Handles mouse leaving the tree view and clears the hover state.
public override void OnMouseLeft()
OnMouseMoved()
Handles mouse movement and updates the hover state of nodes.
public override void OnMouseMoved()
OnTouchDoubleClick()
Handles touch double-click events and toggles node expansion if clicked on the mark.
public override void OnTouchDoubleClick()
OnTouchDown()
Handles touch down events and selects the node at the touch position.
public override void OnTouchDown()
RemoveAllSubNodes()
Removes all nodes from the tree.
public void RemoveAllSubNodes()
Events
SelectionChanged
Occurs when the selected node changes.
public event MyraEventHandler SelectionChanged