Interactivity in WinUI TreeView

6 Sep 20212 minutes to read

This section explains about how to interact with TreeView and its items.

Interacting with TreeView items

ItemTapped event

The ItemTapped event will be triggered whenever tapping the item. The ItemTappedEventArgs has the following members which provides the information for ItemTapped event:

  • Node: Gets the TreeViewNode and 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 will be triggered whenever double tapping the item. The ItemDoubleTappedEventArgs has the following members providing information for the ItemDoubleTapped event:

  • Node: Gets the TreeViewNode and 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 will be triggered whenever the item is long pressed. The
ItemHoldingEventArgs has the following members which provides the information for ItemHolding event:

  • Node: Gets the TreeViewNode and data associated with the hold item as its arguments.
  • Position: Gets the touch position in the hold 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();
}