Interactivity in WinUI TreeView

8 Jul 20262 minutes to read

This section explains how to interact with the TreeView and its items using the following gesture events:

  • ItemTapped - Triggered when an item is tapped.
  • ItemDoubleTapped - Triggered when an item is double-tapped.
  • ItemHolding - Triggered when an item is long pressed.

Interacting with TreeView items

ItemTapped event

The ItemTapped event is triggered whenever an item is tapped. The ItemTappedEventArgs has the following members which provide the information for the ItemTapped event:

  • Node: Gets the TreeViewNode and the data associated with the tapped item as its arguments.
  • Position: Gets the touch position in the tapped item.
  • Handled: Gets or sets whether the event is handled or not.
treeView.ItemTapped += treeView_ItemTapped;

private async void treeView_ItemTapped(object sender, ItemTappedEventArgs e)
{
    var dialog = new MessageDialog("Tapped Item: " + (e.Node.Content as Folder).FileName);
    await dialog.ShowAsync();
}

ItemDoubleTapped event

The ItemDoubleTapped event is triggered whenever an item is double-tapped. The ItemDoubleTappedEventArgs has the following members providing information for the ItemDoubleTapped event:

  • Node: Gets the TreeViewNode and the data associated with the double-tapped item as its arguments.
  • Position: Gets the touch position in the double-tapped item.
  • Handled: Gets or sets whether the event is handled or not.
treeView.ItemDoubleTapped += treeView_ItemDoubleTapped;

private async void treeView_ItemDoubleTapped(object sender, ItemDoubleTappedEventArgs e)
{
    var dialog = new MessageDialog("DoubleTapped Item: " + (e.Node.Content as Folder).FileName);
    await dialog.ShowAsync();
}

ItemHolding event

The ItemHolding event is triggered whenever an item is long pressed. The
ItemHoldingEventArgs has the following members which provide the information for the ItemHolding event:

  • Node: Gets the TreeViewNode and the data associated with the held item as its arguments.
  • Position: Gets the touch position in the held item.
treeView.ItemHolding += treeView_ItemHolding;

private async void treeView_ItemHolding(object sender, ItemHoldingEventArgs e)
{
    var dialog = new MessageDialog("HoldItem: " + (e.Node.Content as Folder).FileName);
    await dialog.ShowAsync();
}