Table of Contents

Class TreeViewItem

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

An item in a TreeView.

[TemplatePart("PART_Header", typeof(Control))]
[PseudoClasses(new string[] { ":pressed", ":selected" })]
public class TreeViewItem : HeaderedItemsControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider, ISelectable
Inheritance
TreeViewItem
Implements
Inherited Members
Extension Methods

Constructors

TreeViewItem()

public TreeViewItem()

Fields

CollapsedEvent

Defines the Collapsed event.

public static readonly RoutedEvent<RoutedEventArgs> CollapsedEvent

Field Value

RoutedEvent<RoutedEventArgs>

ExpandedEvent

Defines the Expanded event.

public static readonly RoutedEvent<RoutedEventArgs> ExpandedEvent

Field Value

RoutedEvent<RoutedEventArgs>

IsExpandedProperty

Defines the IsExpanded property.

public static readonly StyledProperty<bool> IsExpandedProperty

Field Value

StyledProperty<bool>

IsSelectedProperty

Defines the IsSelected property.

public static readonly StyledProperty<bool> IsSelectedProperty

Field Value

StyledProperty<bool>

LevelProperty

Defines the Level property.

public static readonly DirectProperty<TreeViewItem, int> LevelProperty

Field Value

DirectProperty<TreeViewItem, int>

Properties

IsExpanded

Gets or sets a value indicating whether the item is expanded to show its children.

public bool IsExpanded { get; set; }

Property Value

bool

IsSelected

Gets or sets the selection state of the item.

public bool IsSelected { get; set; }

Property Value

bool

Level

Gets the level/indentation of the item.

public int Level { get; }

Property Value

int

Methods

ContainerForItemPreparedOverride(Control, object?, int)

Called when a container has been fully prepared to display an item.

protected override void ContainerForItemPreparedOverride(Control container, object? item, int index)

Parameters

container Control

The container control.

item object

The item being displayed.

index int

The index of the item being displayed.

Remarks

This method will be called when a container has been fully prepared and added to the logical and visual trees, but may be called before a layout pass has completed. It is called immediately before the ContainerPrepared event is raised.

CreateContainerForItemOverride(object?, int, object?)

Creates or a container that can be used to display an item.

protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)

Parameters

item object
index int
recycleKey object

Returns

Control

NeedsContainerOverride(object?, int, out object?)

Determines whether the specified item can be its own container.

protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)

Parameters

item object

The item to check.

index int

The index of the item.

recycleKey object

When the method returns, contains a key that can be used to locate a previously recycled container of the correct type, or null if the item cannot be recycled. If the item is its own container then by definition it cannot be recycled, so recycleKey shoud be set to null.

Returns

bool

true if the item needs a container; otherwise false if the item can itself be used as a container.

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)

Called when the styled element is added to a rooted logical tree.

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)

Parameters

e LogicalTreeAttachmentEventArgs

The event args.

OnCreateAutomationPeer()

Returns a new, type-specific AutomationPeer implementation for the control.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnHeaderDoubleTapped(TappedEventArgs)

Invoked when the DoubleTapped event occurs in the header.

protected virtual void OnHeaderDoubleTapped(TappedEventArgs e)

Parameters

e TappedEventArgs

OnKeyDown(KeyEventArgs)

Handles directional navigation within the ItemsControl.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

The key events.

OnRequestBringIntoView(RequestBringIntoViewEventArgs)

protected virtual void OnRequestBringIntoView(RequestBringIntoViewEventArgs e)

Parameters

e RequestBringIntoViewEventArgs

PrepareContainerForItemOverride(Control, object?, int)

Prepares the specified element to display the specified item.

protected override void PrepareContainerForItemOverride(Control container, object? item, int index)

Parameters

container Control

The element that's used to display the specified item.

item object

The item to display.

index int

The index of the item to display.

Events

Collapsed

Occurs after the TreeViewItem has collapsed to hide its children.

public event EventHandler<RoutedEventArgs>? Collapsed

Event Type

EventHandler<RoutedEventArgs>

Expanded

Occurs after the TreeViewItem has expanded to show its children.

public event EventHandler<RoutedEventArgs>? Expanded

Event Type

EventHandler<RoutedEventArgs>