Class TreeViewItem
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
ExpandedEvent
Defines the Expanded event.
public static readonly RoutedEvent<RoutedEventArgs> ExpandedEvent
Field Value
IsExpandedProperty
Defines the IsExpanded property.
public static readonly StyledProperty<bool> IsExpandedProperty
Field Value
IsSelectedProperty
Defines the IsSelected property.
public static readonly StyledProperty<bool> IsSelectedProperty
Field Value
LevelProperty
Defines the Level property.
public static readonly DirectProperty<TreeViewItem, int> LevelProperty
Field Value
Properties
IsExpanded
Gets or sets a value indicating whether the item is expanded to show its children.
public bool IsExpanded { get; set; }
Property Value
IsSelected
Gets or sets the selection state of the item.
public bool IsSelected { get; set; }
Property Value
Level
Gets the level/indentation of the item.
public int Level { get; }
Property Value
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
ControlThe container control.
item
objectThe item being displayed.
index
intThe 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
Returns
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
objectThe item to check.
index
intThe index of the item.
recycleKey
objectWhen 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
TemplateAppliedEventArgsThe event args.
OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)
Called when the styled element is added to a rooted logical tree.
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
Parameters
e
LogicalTreeAttachmentEventArgsThe 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
OnKeyDown(KeyEventArgs)
Handles directional navigation within the ItemsControl.
protected override void OnKeyDown(KeyEventArgs e)
Parameters
e
KeyEventArgsThe key events.
OnRequestBringIntoView(RequestBringIntoViewEventArgs)
protected virtual void OnRequestBringIntoView(RequestBringIntoViewEventArgs e)
Parameters
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
ControlThe element that's used to display the specified item.
item
objectThe item to display.
index
intThe 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
Expanded
Occurs after the TreeViewItem has expanded to show its children.
public event EventHandler<RoutedEventArgs>? Expanded