NavigationView.Expanding Event

Definition

Occurs when a node in the tree starts to expand.

This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces).

// Register
event_token Expanding(TypedEventHandler<NavigationView, NavigationViewItemExpandingEventArgs const&> const& handler) const;

// Revoke with event_token
void Expanding(event_token const* cookie) const;

// Revoke with event_revoker
NavigationView::Expanding_revoker Expanding(auto_revoke_t, TypedEventHandler<NavigationView, NavigationViewItemExpandingEventArgs const&> const& handler) const;
public event TypedEventHandler<NavigationView,NavigationViewItemExpandingEventArgs> Expanding;
Public Custom Event Expanding As TypedEventHandler(Of NavigationView, NavigationViewItemExpandingEventArgs) 
<NavigationView Expanding="eventhandler" />

Event Type

Examples

The following example creates a hierarchical NavigationView and sets up an event handler for the Expanding event called OnItemExpanding. In this event handler, the expanded item's Content property is set to display in the ExpandingItemLabel TextBlock.

<muxc:NavigationView x:Name="navview"
    MenuItemsSource="{x:Bind categories, Mode=OneWay}"
    Expanding="OnItemExpanding"
    Collapsed="OnItemCollapsed"
    PaneDisplayMode="Left">

    <StackPanel Margin="10,10,0,0">
        <TextBlock Margin="0,10,0,0" x:Name="ExpandingItemLabel" Text="Last Expanding: N/A"/>
        <TextBlock x:Name="CollapsedItemLabel" Text="Last Collapsed: N/A"/>
    </StackPanel>
</muxc:NavigationView>
private void OnItemExpanding(object sender, NavigationViewItemExpandingEventArgs e)
{
    var nvib = e.ExpandingItemContainer;
    var name = "Last Expanding: " + nvib.Content.ToString();
    ExpandingItemLabel.Text = name;
}

Remarks

In order to fill in nodes as they're expanding, set the HasUnrealizedChildren property to true, and then add the children during this Expanding event. See the TreeView example fill a node when it's expanding.

Analogous to TreeView.Expanding event.

Applies to