Interactivity in WPF TreeView
18 Nov 20182 minutes to read
This section explains how to interact with the WPF TreeView control and its items.
Interacting with TreeView items
ItemTapped event
The ItemTapped event is triggered whenever an item is tapped. ItemTappedEventArgs has the following members, which provide information for the ItemTapped event:
-
Node: Gets the TreeViewNode and the data associated with the tapped item. -
Position: Gets the touch position in the tapped item. -
Handled: Gets or sets whether the event is handled.
sfTreeView.ItemTapped += SfTreeView_ItemTapped;
private void SfTreeView_ItemTapped(object sender, ItemTappedEventArgs e)
{
MessageBox.Show("Tapped Item: " + (e.Node.Content as Model).State);
}ItemDoubleTapped event
The ItemDoubleTapped event is triggered whenever an item is double-tapped. The ItemDoubleTappedEventArgs has the following members, which provide information for the ItemDoubleTapped event:
-
Node: Gets the TreeViewNode and the data associated with the double-tapped item. -
Position: Gets the touch position in the double-tapped item. -
Handled: Gets or sets whether the event is handled.
sfTreeView.ItemDoubleTapped += SfTreeView_ItemDoubleTapped;
private void SfTreeView_ItemDoubleTapped(object sender, ItemDoubleTappedEventArgs e)
{
MessageBox.Show("DoubleTapped Item: " + (e.Node.Content as Model).State);
}ItemHolding event
The ItemHolding event is triggered whenever an item is long-pressed (held). ItemHoldingEventArgs has the following members, which provide information for the ItemHolding event:
-
Node: Gets the TreeViewNode and the data associated with the hold item as its arguments. -
Position: Gets the touch position in the hold item.
sfTreeView.ItemHolding += SfTreeView_ItemHolding;
private void SfTreeView_ItemHolding(object sender, ItemHoldingEventArgs e)
{
MessageBox.Show("HoldItem: " + (e.Node.Content as Model).State);
}You can refer to our WPF TreeView feature tour page for its key feature highlights. You can also explore our WPF TreeView example to know how to represent hierarchical data in a tree-like structure with expand and collapse node options.