Events in .NET MAUI Tab View

This section provides information about the events available in the .NET MAUI Tab View control.

Tab Item Tapped event

The TabItemTapped event will be triggered whenever tapping the Tab.The TabItemTappedEventArgs provides the following properties:

  • TabItem : Gets the selected tab item of Tab View control.
  • Cancel : Gets or sets a value indicating whether the event should be canceled.
<tabView:SfTabView x:Name="tabView" TabItemTapped="TabView_TabItemTapped" />
tabView.SelectionChanged += TabView_TabItemTapped;
private void TabView_TabItemTapped(object sender, TabItemTappedEventArgs e)
{
   // Acces the Selected Tab Item Property
    e.TabItem.FontSize = 26;

   // Cancel the event if needed
    e.Cancel = true;
}

Selection Changing event

The SelectionChanging event notifies before the selection changes, tapping the tab header, and dynamically setting the SelectedIndex property of SfTabView. The SelectionChangingEventArgs provides the following properties:

  • Index - Gets the index value of the item that is about to be selected.

  • Cancel - Gets or sets a boolean value indicating whether the selection of the tab item should be canceled.

<tabView:SfTabView x:Name="tabView" SelectionChanging="TabView_SelectionChanging" />
tabView.SelectionChanging += TabView_SelectionChanging;
private void TabView_SelectionChanging(object sender, SelectionChangingEventArgs e)
{
    // Access the index value of the item that is being selected.
    var selectionChangingIndex =  e.Index;

    // if we set Cancel as true then the tabbed item could not selected.
    e.Cancel = true;
}

Selection Changed event

The SelectionChanged event is used to notify when the selection is changed by swiping or dynamically setting the SelectedIndex property of SfTabView. The TabSelectionChangedEventArgs provides the following properties:

  • NewValue : Gets the index of currently selected tab item.
  • OldValue : Gets the index of previously selected tab item.
  • Handled : Gets or sets a value indicating whether the SelectionChanged event is handled.
<tabView:SfTabView x:Name="tabView" SelectionChanged="TabView_SelectionChanged" />
tabView.SelectionChanged += TabView_SelectionChanged;
private void TabView_SelectionChanged(object sender, TabSelectionChangedEventArgs e)
{
    // Access the new and old Index
    double newValue = e.NewIndex;
    double oldValue = e.OldIndex;

    // if we set handled true other SelectionChanged event can't trigger
    e.Handled = true;
}

See also

How to convert events into commands in .NET MAUI TabView?