Sidebar
An app sidebar with groups of items that collapses to a rail of icons.
ShellUI for Blazor's sidebar is a larger set of parts, so the preview below is built from HTML and the ShellUI tokens to match the native component.
Installation
shellui-native add sidebar
Platforms: MAUI · Avalonia. Also installs icon, element-extensions.
Usage
Basic
Home
Pick a page in the sidebar, or collapse it to a rail of icons.
<Grid ColumnDefinitions="Auto,*">
<ui:Sidebar x:Name="AppSidebar" SelectedValue="home" SelectedValueChanged="OnPageChanged">
<ui:Sidebar.Header>
<HorizontalStackLayout Spacing="8" Padding="10,6">
<ui:Icon Name="Sparkles" Size="20" />
<ui:ShellLabel Text="ShellUI Native" Size="Sm" Weight="Semibold" />
</HorizontalStackLayout>
</ui:Sidebar.Header>
<ui:SidebarGroup Label="Workspace">
<ui:SidebarItem Value="home" Text="Home" Icon="House" />
<ui:SidebarItem Value="inbox" Text="Inbox" Icon="Inbox" Badge="12" />
<ui:SidebarItem Value="dashboard" Text="Dashboard" Icon="LayoutDashboard" />
</ui:SidebarGroup>
<ui:SidebarGroup Label="Account">
<ui:SidebarItem Value="settings" Text="Settings" Icon="Settings" />
<ui:SidebarItem Text="Log out" Icon="LogOut" Clicked="OnLogOut" />
</ui:SidebarGroup>
</ui:Sidebar>
<VerticalStackLayout Grid.Column="1" Padding="16">
<ui:Button Icon="PanelLeft" Size="Icon" Variant="Outline" Clicked="OnToggleSidebar" />
</VerticalStackLayout>
</Grid><Grid ColumnDefinitions="Auto,*">
<ui:Sidebar x:Name="AppSidebar" SelectedValue="home" SelectedValueChanged="OnPageChanged">
<ui:Sidebar.Header>
<StackPanel Orientation="Horizontal" Spacing="8" Margin="10,6">
<ui:Icon Kind="Sparkles" Size="20" />
<ui:ShellLabel Text="ShellUI Native" Size="Sm" Weight="Semibold" />
</StackPanel>
</ui:Sidebar.Header>
<ui:SidebarGroup Label="Workspace">
<ui:SidebarItem Value="home" Text="Home" Icon="House" />
<ui:SidebarItem Value="inbox" Text="Inbox" Icon="Inbox" Badge="12" />
<ui:SidebarItem Value="dashboard" Text="Dashboard" Icon="LayoutDashboard" />
</ui:SidebarGroup>
<ui:SidebarGroup Label="Account">
<ui:SidebarItem Value="settings" Text="Settings" Icon="Settings" />
<ui:SidebarItem Text="Log out" Icon="LogOut" Clicked="OnLogOut" />
</ui:SidebarGroup>
</ui:Sidebar>
<StackPanel Grid.Column="1" Margin="16">
<ui:Button Icon="PanelLeft" Size="Icon" Variant="Outline" Clicked="OnToggleSidebar" />
</StackPanel>
</Grid>Put the sidebar in an Auto column next to your content. It is 256px wide; an item with a Value becomes the SelectedValue when pressed, and an item without one just raises Clicked.
Collapsing
IsCollapsed (or Toggle()) shrinks the sidebar to a 56px rail that shows the icons only, animating the width:
private void OnToggleSidebar(object? sender, EventArgs e) => AppSidebar.Toggle();
The header and footer are your own views, so hide what doesn't fit the rail in IsCollapsedChanged.
On phones
A fixed column takes too much of a phone screen. Put the Sidebar inside a Sheet there and open it from a menu button.
MAUI and Avalonia
- On Avalonia the items are tab stops, pressed with Enter or Space.
- On Avalonia the groups are collected in
Groupsand a group's items inItems.
API
Sidebar
XAML children go to Groups.
| Property | Type | Default | Description |
|---|---|---|---|
IsCollapsed |
bool |
false |
Shows the icon rail instead of the full sidebar. Two-way bindable. |
SelectedValue |
string |
— | The active item's Value. Two-way bindable. |
ExpandedWidth |
double |
256 |
Width when expanded. |
CollapsedWidth |
double |
56 |
Width of the icon rail. |
Side |
SidebarSide |
Left |
Which edge of the window it sits on; the border is drawn on the other edge. One of Left, Right. |
Header |
View (MAUI) · Control? (Avalonia) |
null |
A view above the groups. |
Footer |
View (MAUI) · Control? (Avalonia) |
null |
A view below the groups. |
| Event | Arguments | Description |
|---|---|---|
IsCollapsedChanged |
bool |
The sidebar collapsed or expanded. |
SelectedValueChanged |
string? |
User input only: setting SelectedValue from code or a binding doesn't raise it. |
| Method | Description |
|---|---|
Toggle() |
Collapses it if expanded, expands it if collapsed. |
SidebarGroup
XAML children go to Items.
| Property | Type | Default | Description |
|---|---|---|---|
Label |
string |
— | Heading above the group's items; hidden on the rail. |
SidebarItem
| Property | Type | Default | Description |
|---|---|---|---|
Text |
string |
— | Item text; hidden on the rail. |
Value |
string |
— | Identifies the item; becomes the sidebar's SelectedValue when pressed. |
Icon |
IconName |
None |
Lucide icon from IconName; None for no icon. |
Badge |
string |
— | Short text at the end of the row, e.g. a count. |
| Event | Arguments | Description |
|---|---|---|
Clicked |
— | Clicked or tapped (or Enter / Space with keyboard focus). |
| Method | Description |
|---|---|
Press() |
Picks the item in code, as a click or Enter/Space would. Avalonia only. |