Skip to main content

DrawerPage

The DrawerPage combines a sliding drawer pane with a main content area, providing a common navigation pattern for applications. It is built on top of SplitView and adds page-based navigation features such as lifecycle events, safe area support, and automatic integration with NavigationPage.

When nested inside a NavigationPage, the drawer icon automatically switches to a back button when the navigation stack has more than one page.

info

DrawerPage is similar to SplitView but adds page-based navigation features such as lifecycle events, safe area support, and automatic integration with NavigationPage.

DrawerPage with the drawer closed DrawerPage with the drawer open

Useful properties

PropertyTypeDefaultDescription
ContentobjectnullThe main content area of the page.
ContentTemplateIDataTemplatenullA data template for the main content.
DrawerobjectnullThe content displayed inside the drawer pane.
DrawerTemplateIDataTemplatenullA data template for the drawer content.
IsOpenboolfalseControls whether the drawer is open.
DrawerLengthdouble320The width (or height) of the drawer when open.
CompactDrawerLengthdouble48The width of the drawer in compact mode.
DrawerBreakpointWidthdouble0The container width at which the drawer automatically switches between overlay and inline modes. A value of 0 disables the breakpoint.
IsGestureEnabledbooltrueEnables swipe gestures to open and close the drawer.
DrawerBehaviorDrawerBehaviorAutoControls drawer visibility behavior. See the DrawerBehavior Values table below.
DrawerLayoutBehaviorDrawerLayoutBehaviorOverlayHow the drawer interacts with the content area. See the DrawerLayoutBehavior Values table below.
DrawerPlacementDrawerPlacementLeftThe side where the drawer appears. See the DrawerPlacement Values table below.
DrawerHeaderobjectnullContent displayed at the top of the drawer.
DrawerFooterobjectnullContent displayed at the bottom of the drawer.
DrawerIconobjectnullAn icon shown in the drawer toggle button.
DrawerBackgroundIBrushnullThe brush used for the drawer background.
DrawerHeaderBackgroundIBrushnullThe brush used for the drawer header background.
DrawerHeaderForegroundIBrushnullThe brush used for the drawer header foreground.
DrawerFooterBackgroundIBrushnullThe brush used for the drawer footer background.
DrawerFooterForegroundIBrushnullThe brush used for the drawer footer foreground.
BackdropBrushIBrushnullThe brush used for the overlay backdrop when the drawer is open.
DisplayModeSplitViewDisplayModeOverlayControls how the drawer is displayed relative to the content.
HorizontalContentAlignmentHorizontalAlignmentStretchHorizontal alignment of the main content.
VerticalContentAlignmentVerticalAlignmentStretchVertical alignment of the main content.

DrawerBehavior values

ValueDescription
AutoThe drawer opens and closes normally based on user interaction and the breakpoint.
FlyoutThe drawer behaves as a flyout overlay, closing automatically when the user taps outside.
LockedThe drawer stays open and cannot be closed by the user.
DisabledThe drawer is hidden and cannot be opened.

DrawerLayoutBehavior values

ValueDescription
OverlayThe drawer slides over the content. The content area is not resized.
SplitThe drawer pushes the content to the side. Both the drawer and content are visible simultaneously.
CompactOverlayA narrow strip of the drawer is always visible (showing icons). When opened, the drawer overlays the content.
CompactInlineA narrow strip of the drawer is always visible. When opened, the drawer pushes the content aside.

DrawerPlacement values

ValueDescription
LeftThe drawer appears on the left side.
RightThe drawer appears on the right side.
TopThe drawer appears at the top.
BottomThe drawer appears at the bottom.

Events

EventDescription
OpenedRaised when the drawer finishes opening.
ClosingRaised when the drawer is about to close. Set Cancel = true on the event args to prevent closing.
ClosedRaised when the drawer finishes closing.

Gestures and keyboard

DrawerPage supports swipe gestures to open and close the drawer on touch-enabled devices. This can be toggled with the IsGestureEnabled property.

On desktop, pressing the Escape key closes the drawer when it is open and focused.

When a DrawerPage is placed inside a NavigationPage, the hamburger menu icon in the header automatically becomes a back button when additional pages are pushed onto the navigation stack. This provides a seamless transition between drawer navigation and hierarchical page navigation without requiring additional code.

Examples

Basic XAML

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="My App"
DrawerLength="280">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" Click="OnHomeClicked" />
<Button Content="Settings" Click="OnSettingsClicked" />
<Button Content="About" Click="OnAboutClicked" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Select an item from the drawer"
Margin="16" FontSize="18" />
</DrawerPage>

Basic code

var drawerPage = new DrawerPage
{
Header = "My App",
DrawerLength = 280,
Drawer = new StackPanel
{
Spacing = 4,
Margin = new Thickness(8),
Children =
{
new Button { Content = "Home" },
new Button { Content = "Settings" },
new Button { Content = "About" }
}
},
Content = new TextBlock
{
Text = "Select an item from the drawer",
Margin = new Thickness(16),
FontSize = 18
}
};

Toggling the drawer

private void ToggleDrawer()
{
myDrawerPage.IsOpen = !myDrawerPage.IsOpen;
}
private void OnSettingsClicked(object sender, RoutedEventArgs e)
{
myDrawerPage.IsOpen = false;
NavigationPage.GetNavigationPage(this)?.Push(new SettingsPage());
}
<DrawerPage xmlns="https://github.com/avaloniaui"
Header="My App">
<DrawerPage.DrawerHeader>
<TextBlock Text="Navigation" FontSize="18"
FontWeight="Bold" Margin="16" />
</DrawerPage.DrawerHeader>

<DrawerPage.DrawerFooter>
<TextBlock Text="v1.0.0" Margin="16" Opacity="0.6" />
</DrawerPage.DrawerFooter>

<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
<Button Content="Profile" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Main content" Margin="16" />
</DrawerPage>
DrawerPage with header and footer

Persistent sidebar (Split)

Use DrawerLayoutBehavior="Split" to keep the drawer always visible alongside the content.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="My App"
DrawerLayoutBehavior="Split"
DrawerLength="250">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
<Button Content="Settings" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Content is pushed to the side" Margin="16" />
</DrawerPage>
DrawerPage in split mode

Compact navigation rail

Use CompactOverlay or CompactInline to show a narrow strip of the drawer (such as icon buttons) when closed, expanding to the full drawer on open.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="My App"
DrawerLayoutBehavior="CompactInline"
CompactDrawerLength="48"
DrawerLength="250">
<DrawerPage.Drawer>
<StackPanel Spacing="4">
<Button Width="48" Content="H" />
<Button Width="48" Content="S" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Content adjusts when drawer opens" Margin="16" />
</DrawerPage>
DrawerPage compact mode collapsed DrawerPage compact mode expanded

Responsive layout

Automatically switch the drawer between overlay and inline based on the container width.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="Responsive App"
DrawerBreakpointWidth="800"
DrawerLayoutBehavior="Split">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
<Button Content="Settings" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Resize the window to see the drawer adapt" Margin="16" />
</DrawerPage>

RTL support

DrawerPage respects the FlowDirection property. When set to RightToLeft, the drawer placement is mirrored automatically.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="RTL App"
FlowDirection="RightToLeft">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="الصفحة الرئيسية" />
<Button Content="الإعدادات" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="محتوى من اليمين إلى اليسار" Margin="16" />
</DrawerPage>
DrawerPage with RTL layout

Right-side drawer

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="Right Drawer"
DrawerPlacement="Right"
DrawerLength="280">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Option A" />
<Button Content="Option B" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="The drawer opens from the right" Margin="16" />
</DrawerPage>
DrawerPage with right-side drawer

Backdrop scrim

Use the BackdropBrush property to add a semi-transparent overlay behind the drawer when it is open in overlay mode.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="Scrim Example"
BackdropBrush="#80000000">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="A scrim appears behind the drawer" Margin="16" />
</DrawerPage>

Cancelling close

Handle the Closing event to prevent the drawer from closing under certain conditions.

private void OnDrawerClosing(object sender, CancelEventArgs e)
{
if (hasUnsavedChanges)
{
e.Cancel = true;
}
}

Responding to open/close

private void OnDrawerOpened(object sender, EventArgs e)
{
Debug.WriteLine("Drawer opened");
}

private void OnDrawerClosed(object sender, EventArgs e)
{
Debug.WriteLine("Drawer closed");
}

MVVM binding

Bind the IsOpen property to a view model for full control over the drawer state.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="MVVM Example"
IsOpen="{Binding IsDrawerOpen}">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" Command="{Binding GoHomeCommand}" />
<Button Content="Settings" Command="{Binding GoSettingsCommand}" />
</StackPanel>
</DrawerPage.Drawer>

<ContentControl Content="{Binding CurrentContent}" />
</DrawerPage>

Custom drawer icon

Replace the default hamburger icon with a custom icon.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="Custom Icon">
<DrawerPage.DrawerIcon>
<PathIcon Data="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
</DrawerPage.DrawerIcon>

<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Custom drawer icon" Margin="16" />
</DrawerPage>

Locked drawer

Use DrawerBehavior="Locked" to keep the drawer permanently open.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="Locked Drawer"
DrawerBehavior="Locked"
DrawerLayoutBehavior="Split"
DrawerLength="250">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
<Button Content="Settings" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="The drawer cannot be closed" Margin="16" />
</DrawerPage>

Disabling the drawer

Use DrawerBehavior="Disabled" to hide the drawer entirely.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="No Drawer"
DrawerBehavior="Disabled">
<TextBlock Text="The drawer is disabled on this page" Margin="16" />
</DrawerPage>

CrossFade transition

Apply a transition when the drawer opens or closes.

<DrawerPage xmlns="https://github.com/avaloniaui"
Header="Transitions">
<DrawerPage.PageTransition>
<CrossFade Duration="0:0:0.25" />
</DrawerPage.PageTransition>

<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
</StackPanel>
</DrawerPage.Drawer>

<TextBlock Text="Smooth transitions" Margin="16" />
</DrawerPage>

Drawer inside NavigationPage

When wrapped in a NavigationPage, the hamburger menu icon automatically becomes a back button when pages are pushed.

<NavigationPage xmlns="https://github.com/avaloniaui">
<DrawerPage Header="Home">
<DrawerPage.Drawer>
<StackPanel Spacing="4" Margin="8">
<Button Content="Home" />
<Button Content="Settings" />
</StackPanel>
</DrawerPage.Drawer>

<StackPanel Margin="16" Spacing="8">
<TextBlock Text="Home Page" FontSize="24" />
<Button Content="Go to Details" Click="OnGoToDetails" />
</StackPanel>
</DrawerPage>
</NavigationPage>

See also