avalonia-controls-layout
Use when working with Avalonia layout container controls: Border, ScrollViewer, SplitView, Expander, GroupBox (12.0+), Viewbox, or Panel variants (Grid, StackPanel, WrapPanel, DockPanel, UniformGrid, Canvas). Covers container-specific API, properties, scroll configuration, and layout pitfalls in Avalonia 12.
linuxdevel · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add linuxdevel/Avalonia-skills --skill avalonia-controls-layout技能说明
name: avalonia-controls-layout description: Use when working with Avalonia layout container controls: Border, ScrollViewer, SplitView, Expander, GroupBox (12.0+), Viewbox, or Panel variants (Grid, StackPanel, WrapPanel, DockPanel, UniformGrid, Canvas). Covers container-specific API, properties, scroll configuration, and layout pitfalls in Avalonia 12.
Avalonia Layout Controls
Overview
Layout controls are containers that position and constrain child controls. See avalonia-layout for general sizing/alignment concepts. This skill covers the container control APIs.
Border
Single-child container. Adds background, border, rounded corners, padding, and shadows.
| Property | Type | Notes |
|---|---|---|
Background | IBrush | Fill color |
BorderBrush | IBrush | Border color |
BorderThickness | Thickness | 1 or 1,2,1,2 (L,T,R,B) |
CornerRadius | CornerRadius | 8 or 8,0,8,0 (TL,TR,BR,BL) |
Padding | Thickness | Inner spacing |
BoxShadow | BoxShadows | Drop shadow(s) |
Child | Control | Single child only |
<!-- Card style -->
<Border Background="White"
CornerRadius="8"
BorderBrush="#E0E0E0"
BorderThickness="1"
Padding="16"
BoxShadow="0 2 8 0 #20000000">
<StackPanel Spacing="8">
<TextBlock Text="Card Title" FontWeight="SemiBold" FontSize="16"/>
<TextBlock Text="Card body content goes here." TextWrapping="Wrap"/>
</StackPanel>
</Border>
<!-- Divider line using Border -->
<Border Height="1" Background="#E0E0E0" Margin="0,8"/>
<!-- Multiple box shadows -->
<Border BoxShadow="0 1 3 0 #1A000000, 0 4 6 0 #0D000000" CornerRadius="6" Padding="12">
<TextBlock Text="Elevated card"/>
</Border>
Important:
Borderonly accepts one child. Wrap multiple children in aPanel,StackPanel, orGrid.
ScrollViewer
Adds scrollbars to content that overflows its bounds.
| Property | Type | Notes |
|---|---|---|
HorizontalScrollBarVisibility | ScrollBarVisibility | Auto, Visible, Hidden, Disabled |
VerticalScrollBarVisibility | ScrollBarVisibility | Auto, Visible, Hidden, Disabled |
Offset | Vector | Programmatic scroll position |
Extent | Size | Total content size |
Viewport | Size | Visible area size |
AllowAutoHide | bool | Hides scrollbar when not hovering |
HorizontalSnapPointsType | SnapPointsType | Snap behavior |
ScrollBarVisibility values:
| Value | Behavior |
|---|---|
Auto | Shows when content overflows |
Visible | Always shown |
Hidden | Never shown, but scrolling still works |
Disabled | Disables scrolling in that direction |
<!-- Standard vertical scroll -->
<ScrollViewer VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<StackPanel>
<!-- many items -->
</StackPanel>
</ScrollViewer>
<!-- Horizontal scroll (e.g. wide table) -->
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Disabled">
<Grid Width="1200"><!-- wide content --></Grid>
</ScrollViewer>
// Programmatic scroll
scrollViewer.Offset = new Vector(0, 500);
// Scroll to end
scrollViewer.ScrollToEnd();
// Subscribe to scroll events
scrollViewer.ScrollChanged += (s, e) =>
{
bool atBottom = scrollViewer.Offset.Y >= scrollViewer.ScrollBarMaximum.Y;
};
Pitfall:
ScrollViewerinsideStackPanelnever scrolls becauseStackPanelgives infinite height. Fix: use aGridrow withHeight="*"or set an explicitHeighton theScrollViewer.
SplitView
Two-region layout: a collapsible pane and main content area.
| Property | Type | Notes |
|---|---|---|
IsPaneOpen | bool | TwoWay — controls pane visibility |
OpenPaneLength | double | Width when expanded |
CompactPaneLength | double | Width when compact (icon-only) |
DisplayMode | SplitViewDisplayMode | See table below |
PanePlacement | SplitViewPanePlacement | Left (default), Right |
Pane | object | Pane content |
Content | object | Main content area |
DisplayMode values:
| Mode | Behavior |
|---|---|
Overlay | Pane overlaps content when open |
Inline | Pane pushes content when open |
CompactOverlay | Shows CompactPaneLength strip; expands over content |
CompactInline | Shows CompactPaneLength strip; expands pushing content |
<SplitView IsPaneOpen="{Binding IsNavOpen}"
DisplayMode="CompactInline"
OpenPaneLength="220"
CompactPaneLength="48">
<SplitView.Pane>
<StackPanel Spacing="4" Margin="4">
<Button Command="{Binding NavHomeCommand}" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Spacing="12">
<PathIcon Data="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" Width="20" Height="20"/>
<TextBlock Text="Home" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Command="{Binding NavSettingsCommand}" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Spacing="12">
<PathIcon Data="M19.14 12.94..." Width="20" Height="20"/>
<TextBlock Text="Settings" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
</SplitView.Pane>
<ContentControl Content="{Binding CurrentPage}"/>
</SplitView>
Note:
PaneandContentare set via XAML property element syntax, not as items in aChildrencollection.
Expander
Collapsible section with a header.
| Property | Type | Notes |
|---|---|---|
Header | object | Always-visible header (string or XAML) |
IsExpanded | bool | TwoWay — controls expand state |
ExpandDirection | ExpandDirection | Down (default), Up, Left, Right |
ContentTransition |