Share via


NavigationView.Collapsed Event

Definition

Occurs when a node in the tree is collapsed.

// Register
event_token Collapsed(TypedEventHandler<NavigationView, NavigationViewItemCollapsedEventArgs const&> const& handler) const;

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

// Revoke with event_revoker
NavigationView::Collapsed_revoker Collapsed(auto_revoke_t, TypedEventHandler<NavigationView, NavigationViewItemCollapsedEventArgs const&> const& handler) const;
public event TypedEventHandler<NavigationView,NavigationViewItemCollapsedEventArgs> Collapsed;
function onCollapsed(eventArgs) { /* Your code */ }
navigationView.addEventListener("collapsed", onCollapsed);
navigationView.removeEventListener("collapsed", onCollapsed);
- or -
navigationView.oncollapsed = onCollapsed;
Public Custom Event Collapsed As TypedEventHandler(Of NavigationView, NavigationViewItemCollapsedEventArgs) 
<NavigationView Collapsed="eventhandler" />

Event Type

Examples

The following example creates a hierarchical NavigationView and sets up an event handler for the Collapsed event called OnItemCollapsed. In this event handler, the last collapsed item's Content property is set to display in the CollapsedItemLabel TextBlock.

<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>    
</NavigationView>
private void OnItemCollapsed(object sender, NavigationViewItemCollapsedEventArgs e)
{
    var nvib = e.CollapsedItemContainer;
    var name = "Last Collapsed: " + nvib.Content;
    CollapsedItemLabel.Text = name;
}

Remarks

Analogous to TreeView.Collapse

Applies to