avalonia-controls-navigation
Use when working with Avalonia navigation controls: TabControl (TabItem.IconTemplate 12.0+), Menu, ContextMenu, Flyout (FlyoutBase.IsOpen 12.0+), NativeMenu/NativeDock.Menu, TrayIcon, and the page-based navigation set added in 12.0 (Page, ContentPage, NavigationPage, TabbedPage, DrawerPage, CarouselPage, CommandBar). Covers tab binding, menu command wiring, access keys, context menu DataContext, tray icons, and mobile-style page stacks. HamburgerMenu does not exist in core.
linuxdevel · Static checks on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add linuxdevel/Avalonia-skills --skill avalonia-controls-navigationAbout this skill
name: avalonia-controls-navigation description: Use when working with Avalonia navigation controls: TabControl (TabItem.IconTemplate 12.0+), Menu, ContextMenu, Flyout (FlyoutBase.IsOpen 12.0+), NativeMenu/NativeDock.Menu, TrayIcon, and the page-based navigation set added in 12.0 (Page, ContentPage, NavigationPage, TabbedPage, DrawerPage, CarouselPage, CommandBar). Covers tab binding, menu command wiring, access keys, context menu DataContext, tray icons, and mobile-style page stacks. HamburgerMenu does not exist in core.
Avalonia Navigation Controls
Overview
Navigation controls let users move between views or trigger application commands. All menu controls support Command binding and keyboard shortcuts via InputGesture.
| Need | Use | Availability |
|---|---|---|
| Desktop tabs | TabControl | all |
| Touch-first page stack, drawer, bottom tabs (mobile style) | NavigationPage / DrawerPage / TabbedPage / ContentPage / CarouselPage | 12.0+ (core Avalonia package) |
| Toolbar with overflow | CommandBar | 12.0+ |
| Side nav on 11.x / desktop shell | SplitView + ListBox, or FluentAvalonia NavigationView | all |
HamburgerMenu | not in Avalonia core — use DrawerPage (12.0+), SplitView, or a community lib | — |
12.0+ touch/pen:
TabControl/ListBox/TreeViewselect on pointer release;TabItem/ListBoxItem/TreeViewItemhandle selection themselves.
TabControl
Displays content in tabbed panels. Tabs can be static (inline TabItem) or dynamic (bound ItemsSource).
| Property | Type | Notes |
|---|---|---|
SelectedIndex | int | TwoWay |
SelectedItem | object | TwoWay |
TabStripPlacement | Dock | Top (default), Bottom, Left, Right |
ItemsSource | IEnumerable | For dynamic tabs |
ItemTemplate | DataTemplate | Header template for dynamic tabs |
ContentTemplate | DataTemplate | Body template for dynamic tabs |
TabItem properties:
| Property | Notes |
|---|---|
Header | Tab label (string or XAML) |
Content | Tab body |
IsEnabled | Disables individual tab |
IsSelected | Set programmatically |
Icon / IconTemplate | Icon next to the header; IconTemplate (IDataTemplate) is 12.0+ |
IndicatorTemplate | Selection indicator template |
<!-- Static tabs -->
<TabControl SelectedIndex="{Binding ActiveTabIndex}" TabStripPlacement="Top">
<TabItem Header="Dashboard">
<views:DashboardView/>
</TabItem>
<TabItem Header="Reports">
<views:ReportsView/>
</TabItem>
<TabItem Header="Settings" IsEnabled="{Binding IsAdmin}">
<views:SettingsView/>
</TabItem>
</TabControl>
<!-- Custom tab header with icon -->
<TabControl>
<TabItem>
<TabItem.Header>
<StackPanel Orientation="Horizontal" Spacing="6">
<PathIcon Data="M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"
Width="14" Height="14"/>
<TextBlock Text="Dashboard" VerticalAlignment="Center"/>
</StackPanel>
</TabItem.Header>
<views:DashboardView/>
</TabItem>
</TabControl>
Icon template (12.0+):
<TabControl ItemsSource="{Binding Tabs}">
<TabControl.Styles>
<Style Selector="TabItem">
<Setter Property="Header" Value="{Binding Title}"/>
<Setter Property="Icon" Value="{Binding IconData}"/>
<Setter Property="IconTemplate">
<Setter.Value>
<DataTemplate x:DataType="x:String">
<PathIcon Data="{Binding}" Width="14" Height="14"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Styles>
</TabControl>
(11.x: put the icon inside a custom Header as shown above.)
Dynamic tabs (ViewModel-driven):
<TabControl ItemsSource="{Binding Tabs}"
SelectedItem="{Binding ActiveTab}">
<TabControl.ItemTemplate>
<!-- Header template -->
<DataTemplate x:DataType="vm:TabVm">
<StackPanel Orientation="Horizontal" Spacing="6">
<TextBlock Text="{Binding Title}" VerticalAlignment="Center"/>
<Button Content="✕"
Command="{Binding $parent[TabControl].DataContext.CloseTabCommand}"
CommandParameter="{Binding}"
Padding="4,0" FontSize="10"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<!-- Body template -->
<DataTemplate x:DataType="vm:TabVm">
<ContentControl Content="{Binding Content}"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
public class TabVm
{
public string Title { get; set; } = "";
public object? Content { get; set; }
}
Page-based Navigation (12.0+)
Touch-first, MAUI-style navigation in the core Avalonia package (namespace Avalonia.Controls, default xmlns). Not available in 11.x. Hierarchy: Page → ContentPage (single content), MultiPage → NavigationPage, SelectingMultiPage → TabbedPage/CarouselPage; DrawerPage derives from Page. ContentPage.Content cannot be a Page (throws InvalidOperationException) — host pages in NavigationPage/TabbedPage/DrawerPage/CarouselPage.
Page members: Header/HeaderTemplate, Icon/IconTemplate, CurrentPage, Navigation (INavigation of parent NavigationPage), IsInNavigationPage, SafeAreaPadding; events Navigating (NavigatingFromEventArgs, set Cancel), NavigatedFrom, NavigatedTo; overrides OnNavigatingFrom/OnNavigatedFrom/OnNavigatedTo (call base). NavigatedTo fires every time the page becomes active (unlike Loaded).
| Control | Purpose | Key members |
|---|---|---|
ContentPage | One piece of content | Content, `ContentTemplat |