Events in .NET MAUI Navigation Drawer (SfNavigationDrawer)
29 Jul 20266 minutes to read
This section explains the built-in events of the .NET MAUI Navigation Drawer control and how to handle them in your application.
The following five built-in events are available in the Navigation Drawer control:
Prerequisites
Before using the SfNavigationDrawer, ensure the following NuGet package is installed in your .NET MAUI project:
Syncfusion.Maui.NavigationDrawer
For step-by-step setup, refer to the Getting Started documentation.
Event life cycle
The events fire in the following order during a state change:
-
DrawerOpening- fires before the open animation starts (cancelable). -
DrawerOpened- fires after the open animation completes. -
DrawerClosing- fires before the close animation starts (cancelable). -
DrawerClosed- fires after the close animation completes. -
DrawerToggled- fires after every state change, alongsideDrawerOpenedorDrawerClosed, and reports the resultingIsOpenstate.
DrawerOpening event
The DrawerOpening event is triggered before the drawer pane opens. You can cancel the open operation by setting the Cancel property of the event argument to true. The event argument is of type DrawerCancelEventArgs.
-
Cancel: Determines if the drawer opening should be canceled.
<navigationDrawer:SfNavigationDrawer x:Name="navigationDrawer"
DrawerOpening="OnDrawerOpening" />SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
navigationDrawer.DrawerOpening += OnDrawerOpening;The DrawerOpening event can be handled in C# as follows:
private void OnDrawerOpening(object sender, DrawerCancelEventArgs e)
{
e.Cancel = true;
}DrawerOpened event
The DrawerOpened event is 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="OnDrawerOpened" />SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
navigationDrawer.DrawerOpened += OnDrawerOpened;The DrawerOpened event can be handled in C# as follows:
private void OnDrawerOpened(object sender, DrawerEventArgs e)
{
// Codes that need to be executed once the drawer is opened.
}DrawerClosing event
The DrawerClosing event is triggered before the drawer pane closes. You can cancel the close operation by setting the Cancel property of the event argument to true. The event argument is of type DrawerCancelEventArgs.
-
Cancel: Determines if the drawer closing should be canceled.
<navigationDrawer:SfNavigationDrawer x:Name="navigationDrawer"
DrawerClosing="OnDrawerClosing" />SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
navigationDrawer.DrawerClosing += OnDrawerClosing;The DrawerClosing event can be handled in C# as follows:
private void OnDrawerClosing(object sender, DrawerCancelEventArgs e)
{
e.Cancel = true;
}DrawerClosed event
The DrawerClosed event is 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="OnDrawerClosed" />SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
navigationDrawer.DrawerClosed += OnDrawerClosed;The DrawerClosed event can be handled in C# as follows:
private void OnDrawerClosed(object sender, DrawerEventArgs e)
{
// Codes that need to be executed once the drawer is closed.
}DrawerToggled event
The DrawerToggled event is a unified state-change notification that fires after the drawer is opened or closed, alongside DrawerOpened or DrawerClosed. The event argument is of type ToggledEventArgs. It exposes the following property:
- IsOpen: Indicates whether the drawer is opened or closed.
<navigationDrawer:SfNavigationDrawer x:Name="navigationDrawer"
DrawerToggled="OnDrawerToggled" />SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
navigationDrawer.DrawerToggled += OnDrawerToggled;The DrawerToggled event can be handled in C# as follows:
private void OnDrawerToggled(object sender, Syncfusion.Maui.NavigationDrawer.ToggledEventArgs e)
{
var isOpen = e.IsOpen;
// Codes that need to be executed once the drawer is toggled.
}