-api-id | -api-type |
---|---|
E:Microsoft.UI.Xaml.Controls.NavigationView.Expanding |
winrt event |
Occurs when a node in the tree starts to expand.
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.
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;
}
<NavigationView Expanding="eventhandler" />