title | page_title | description | position | slug |
---|---|---|---|---|
Events |
.NET MAUI TreeView Documentation - Events |
Review TreeView events that are raised when item is tapped, selected and source is changed. |
7 |
treeview-events |
The .NET MAUI TreeView emits a set of events that allow you to configure the component's behavior in response to specific user actions.
The .NET MAUI TreeView exposes the following events:
-
ItemTapped
—Raised when an item is tapped. TheItemTapped
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
ItemViewTappedEventArgs
object, which has a reference to:- the tapped item through its
Item
(object
) property. - the tapped
View
(ItemView
). - the
Handled
(bool
) property—Indicates whether the event handler has already handled the tap event. When set totrue
, the default handling of the tap event is not executed. When set tofalse
, the default handling of the tap event is executed.
- the tapped item through its
On Android and iOS, when tapping the TreeView item, the item gets expanded. On WinUI and MacCatalyst, the item gets expanded when tapping on the arrow >.
- The
-
ItemHolding
—Raised when an item is held. TheItemHolding
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
ItemViewHoldingEventArgs
object which has a reference to:- the tapped item through its
Item
(object
) property. - the tapped
View
(ItemView
). - the
Handled
(bool
) property—Indicates whether the event handler has already handled the hold event. When set totrue
, the default handling of the hold event is not executed. When set tofalse
, the default handling of the hold event is executed.
- the tapped item through its
- The
-
ItemsSourceChanged
—Raised whenItemsSource
has changed. TheItemsSourceChanged
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - An
EventHandler
object.
- The
-
SelectionChanged
—Raised when the current selection changes. TheSelectionChanged
event handler receives two parameters:- The sender argument, which is of type
object
, but can be cast to theRadTreeView
type. - A
EventArgs
object, which provides information on theSelectionChanged
event.
- The sender argument, which is of type
-
LoadChildrenOnDemand
—Raised when loading an item on demand. TheLoadChildrenOnDemand
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
TreeViewLoadChildrenOnDemandEventArgs
object, which has a reference to:- the item through its
Item
(object
) property.
- the item through its
- The
-
ItemChecked
—Raised when an item is checked after a user interaction. TheItemChecked
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
TreeViewItemViewInteractionEventArgs
object which has a reference to:- the tapped item through its
Item
(object
) property. - the tapped
View
(ItemView
).
- the tapped item through its
- The
-
ItemUnchecked
—Raised when an item is unchecked after a user interaction. TheItemUnchecked
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
TreeViewItemViewInteractionEventArgs
object which has a reference to:- the tapped item through its
Item
(object
) property. - the tapped
View
(ItemView
).
- the tapped item through its
- The
-
ItemExpanded
—Raised when an item is expanded after a user interaction. TheItemExpanded
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
TreeViewItemViewInteractionEventArgs
object which has a reference to:- the tapped item through its
Item
(object
) property. - the tapped
View
(ItemView
).
- the tapped item through its
- The
-
ItemCollapsed
—Raised when an item is collapsed after a user interaction. TheItemCollapsed
event handler receives two parameters:- The
sender
argument, which is of typeobject
, but can be cast to theRadTreeView
type. - A
TreeViewItemViewInteractionEventArgs
object which has a reference to:- the tapped item through its
Item
(object
) property. - the tapped
View
(ItemView
).
- the tapped item through its
- The
The following example demonstrates how to use the ItemTapped
event:
1. Define the RadTreeView
control:
2. Add the ItemTapped
event:
3. Add the data model:
4. Add the ViewModel:
This is the result on Android:
The following example demonstrates how to use the SelectionChanged
event:
1. Define the RadTreeview
control:
2. Add the ItemTapped
event:
3. Add the data model:
4. Add the ViewModel:
This is the result on Android:
For a runnable example demonstrating the TreeView events, see the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and go to TreeView > Events.
- [Expand and Collapse TreeView Items]({%slug treeview-expand-collapse%})
- [CheckBoxes in TreeView]({%slug treeview-checkboxes%})
- [Styling the TreeView Item]({%slug treeview-item-style%})
- [Scrolling options]({%slug treeview-scrolling%})
- [Multiple and Single Selection]({%slug treeview-selection%})
- [Available Commands in .NET MAUI TreeView]({%slug treeview-commands%})