Primary APIs:
TabControl, SplitView, Menu, MenuItemContentControl, TransitioningContentControl, DataTemplateReference docs:
11-user-views-locator-and-tree-patterns.md38-data-templates-and-idatatemplate-selector-patterns.md05-html-shell-navigation-popups-and-layering-patterns.md| Web navigation pattern | Avalonia mapping |
|---|---|
router outlet (<main id="app">) |
ContentControl Content="{CompiledBinding CurrentPageVm}" |
| tabs | TabControl |
| collapsible side nav | SplitView pane |
| top nav menu | Menu + MenuItem |
| breadcrumb row | horizontal stack of controls/text |
HTML/CSS tabs:
<nav class="tabs"><button class="active">Overview</button><button>Billing</button></nav>
Avalonia:
<TabControl SelectedIndex="{CompiledBinding SelectedTabIndex}">
<TabItem Header="Overview" />
<TabItem Header="Billing" />
<TabItem Header="Audit" />
</TabControl>
HTML/CSS:
.layout { display:grid; grid-template-columns: 250px 1fr; }
.breadcrumb { display:flex; gap:8px; }
Avalonia:
<Grid ColumnDefinitions="250,*">
<StackPanel Grid.Column="0" Classes="nav-rail" />
<StackPanel Grid.Column="1" Spacing="10">
<StackPanel Orientation="Horizontal" Spacing="8" Classes="breadcrumb" />
<ContentControl Content="{CompiledBinding CurrentPageVm}" />
</StackPanel>
</Grid>
Use route keys and data templates:
public string CurrentRoute { get; set; } = "dashboard";
public object CurrentPageVm => CurrentRoute switch
{
"dashboard" => DashboardVm,
"users" => UsersVm,
_ => NotFoundVm
};
<ContentControl Content="{CompiledBinding CurrentPageVm}" />
<SplitView OpenPaneLength="250"
CompactPaneLength="64"
DisplayMode="CompactInline"
IsPaneOpen="{CompiledBinding IsNavOpen}">
<SplitView.Pane>
<StackPanel Spacing="6">
<Button Content="Dashboard" Command="{CompiledBinding GoDashboardCommand}" />
<Button Content="Users" Command="{CompiledBinding GoUsersCommand}" />
<Button Content="Billing" Command="{CompiledBinding GoBillingCommand}" />
</StackPanel>
</SplitView.Pane>
<TransitioningContentControl Content="{CompiledBinding CurrentPageVm}" />
</SplitView>
using Avalonia.Controls;
var shell = new SplitView
{
OpenPaneLength = 250,
CompactPaneLength = 64,
DisplayMode = SplitViewDisplayMode.CompactInline,
Pane = new StackPanel
{
Spacing = 6,
Children =
{
new Button { Content = "Dashboard" },
new Button { Content = "Users" },
new Button { Content = "Billing" }
}
},
Content = new TransitioningContentControl()
};
OpenPaneLength, layout columns, and breakpoint state logic.