Events in .NET MAUI Navigation Drawer (SfNavigationDrawer)

There are five built-in events in the SfNavigationDrawer control namely:

DrawerOpening Event

The DrawerOpening event is triggered before the drawer pane is opening. Restrict the drawer from opening by canceling this event by setting the Cancel property in the event argument to true. The event arguments are of type CancelEventArgs. Expose the following property:

  • Cancel: Drawer opening is based on this value.
<navigationdrawer:SfNavigationDrawer x:Name="navigationDrawer" DrawerOpening="navigationDrawer_DrawerOpening"/>
public MainPage()
{
    InitializeComponent();
    navigationDrawer.DrawerOpening += navigationDrawer_DrawerOpening;
}

private void navigationDrawer_DrawerOpening(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
}

DrawerOpened Event

The DrawerOpened event triggered after a drawer is opened.

You can execute your own set of codes once the drawer is opened.

<navigationdrawer:SfNavigationDrawer x:Name="navigationDrawer" DrawerOpened="navigationDrawer_DrawerOpened"/>
public MainPage()
{
    InitializeComponent();
    navigationDrawer.DrawerOpened += navigationDrawer_DrawerOpened;
}

private void navigationDrawer_DrawerOpened(object sender, EventArgs e)
{
    // Codes that need to be executed once the drawer is opened.
}

DrawerClosing Event

The DrawerClosing event is triggered before the drawer pane closes. Restrict the drawer from closing by canceling this event by setting the Cancel property in the event argument to true. The event arguments are of type CancelEventArgs. Expose the following property:

  • Cancel: Drawer closing is based on this value.
<navigationdrawer:SfNavigationDrawer x:Name="navigationDrawer" DrawerClosing="navigationDrawer_DrawerClosing"/>
public MainPage()
{
    InitializeComponent();
    navigationDrawer.DrawerClosing += navigationDrawer_DrawerClosing;
}

private void navigationDrawer_DrawerClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
}

DrawerClosed Event

The DrawerClosed event triggered after a drawer is closed.

You can execute your own set of codes once the drawer is closed.

<navigationdrawer:SfNavigationDrawer x:Name="navigationDrawer" DrawerClosed="navigationDrawer_DrawerClosed"/>
public MainPage()
{
    InitializeComponent();
    navigationDrawer.DrawerClosed += navigationDrawer_DrawerClosed;
}

private void navigationDrawer_DrawerClosed(object sender, EventArgs e)
{
    // Codes that need to be executed once the drawer is closed.
}

DrawerToggled Event

The DrawerToggled event is triggered after a drawer is opened or closed. The event arguments are of type ToggledEventArgs. Expose the following property:

  • IsOpen: This property indicates whether the drawer is opened or closed.
<navigationdrawer:SfNavigationDrawer x:Name="navigationDrawer" DrawerToggled="navigationDrawer_DrawerToggled"/>
public MainPage()
{
    InitializeComponent();
    navigationDrawer.DrawerToggled += navigationDrawer_DrawerToggled;
}

private void navigationDrawer_DrawerToggled(object sender, Syncfusion.Maui.NavigationDrawer.ToggledEventArgs e)
{
    var isOpen = e.IsOpen;
    // Codes that need to be executed once the drawer is toggled.
}