跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
其他技能

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 · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add linuxdevel/Avalonia-skills --skill avalonia-controls-navigation

技能说明


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.

NeedUseAvailability
Desktop tabsTabControlall
Touch-first page stack, drawer, bottom tabs (mobile style)NavigationPage / DrawerPage / TabbedPage / ContentPage / CarouselPage12.0+ (core Avalonia package)
Toolbar with overflowCommandBar12.0+
Side nav on 11.x / desktop shellSplitView + ListBox, or FluentAvalonia NavigationViewall
HamburgerMenunot in Avalonia core — use DrawerPage (12.0+), SplitView, or a community lib—

12.0+ touch/pen: TabControl/ListBox/TreeView select on pointer release; TabItem/ListBoxItem/TreeViewItem handle selection themselves.


TabControl

Displays content in tabbed panels. Tabs can be static (inline TabItem) or dynamic (bound ItemsSource).

PropertyTypeNotes
SelectedIndexintTwoWay
SelectedItemobjectTwoWay
TabStripPlacementDockTop (default), Bottom, Left, Right
ItemsSourceIEnumerableFor dynamic tabs
ItemTemplateDataTemplateHeader template for dynamic tabs
ContentTemplateDataTemplateBody template for dynamic tabs

TabItem properties:

PropertyNotes
HeaderTab label (string or XAML)
ContentTab body
IsEnabledDisables individual tab
IsSelectedSet programmatically
Icon / IconTemplateIcon next to the header; IconTemplate (IDataTemplate) is 12.0+
IndicatorTemplateSelection 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).

ControlPurposeKey members
ContentPageOne piece of contentContent, `ContentTemplat
阅读完整来源 ↗