avalonia-controls-data-display
Use when working with Avalonia data display controls: TextBlock, Label, ItemsControl, ListBox, TableView (12.1+), DataGrid (maintenance mode), TreeDataGrid (commercial), TreeView, or Carousel. Includes a decision table for choosing a list/grid control, compiled-binding rules for DataGrid/TableView columns, touch/pen selection behavior, and Carousel swipe/wrap (12.0+). Note there is no built-in MarkdownViewer; use Markdown.Avalonia. Covers Avalonia 11.3, 12.0 and 12.1.
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-data-displayAbout this skill
name: avalonia-controls-data-display description: Use when working with Avalonia data display controls: TextBlock, Label, ItemsControl, ListBox, TableView (12.1+), DataGrid (maintenance mode), TreeDataGrid (commercial), TreeView, or Carousel. Includes a decision table for choosing a list/grid control, compiled-binding rules for DataGrid/TableView columns, touch/pen selection behavior, and Carousel swipe/wrap (12.0+). Note there is no built-in MarkdownViewer; use Markdown.Avalonia. Covers Avalonia 11.3, 12.0 and 12.1.
Avalonia Data Display Controls
Overview
Data display controls render read-only or selectable information. Pick by need:
| Need | Control | Availability |
|---|---|---|
| Simple repeated items, no selection | ItemsControl | all |
| Selectable list, custom item layout | ListBox | all |
| Read-only table: columns over a collection, no editing (virtualized, row/cell recycling) | TableView | 12.1+ (core Avalonia package) |
| Editable/sortable/grouped grid | DataGrid | Avalonia.Controls.DataGrid package, MIT. Maintenance mode (bug fixes only) since 12.1 — fine for existing apps and 11.x/12.0, don't pick for new read-only grids on 12.1+ |
| Tree + table, advanced editing, hierarchical grid | TreeDataGrid | Avalonia.Controls.TreeDataGrid package. Commercial: requires an Avalonia Accelerate/Pro license (since 11.2); versions independently (12.x line targets Avalonia 12) |
| Hierarchy, single column | TreeView | all |
There is no
MarkdownViewerin Avalonia core. Use the communityMarkdown.Avaloniapackage (orLiveMarkdown.Avalonia).
TextBlock
| Property | Type | Notes |
|---|---|---|
Text | string | Plain text content |
FontSize | double | In device-independent pixels |
FontWeight | FontWeight | Normal, Bold, SemiBold, etc. |
FontStyle | FontStyle | Normal, Italic, Oblique |
TextWrapping | TextWrapping | NoWrap, Wrap, WrapWithOverflow |
TextTrimming | TextTrimming | None, CharacterEllipsis, WordEllipsis |
TextDecorations | TextDecorationCollection | Underline, Strikethrough |
LineHeight | double | Line spacing |
MaxLines | int | Clamps number of displayed lines |
Inlines | InlineCollection | Mixed-format inline content |
<!-- Basic -->
<TextBlock Text="{Binding Title}" FontSize="18" FontWeight="SemiBold"/>
<!-- Trimming with ellipsis -->
<TextBlock Text="{Binding Description}" TextTrimming="CharacterEllipsis" MaxWidth="300"/>
<!-- Inline formatting -->
<TextBlock>
<Run FontWeight="Bold">Important:</Run>
<Run> This is </Run>
<Run Foreground="Red" FontStyle="Italic">critical</Run>
<LineBreak/>
<Run Text="{Binding Detail}"/>
</TextBlock>
<!-- Underline + strikethrough -->
<TextBlock Text="Strike me" TextDecorations="Strikethrough"/>
<TextBlock Text="Link-style" TextDecorations="Underline" Cursor="Hand"/>
Label
| Property | Type | Notes |
|---|---|---|
Content | object | Text or XAML content |
Target | IInputElement | Associates access key with target control |
Use _ prefix in content to define an access key (Alt+key focuses Target).
<Label Content="_Username" Target="{Binding #usernameBox}"/>
<TextBox x:Name="usernameBox" Text="{Binding Username}"/>
<Label Content="_Password" Target="{Binding #passwordBox}"/>
<TextBox x:Name="passwordBox" PasswordChar="•" Text="{Binding Password}"/>
Note:
Labeladds padding and is aContentControl. For pure display, preferTextBlock.
ItemsControl
Base class for all list controls. Use directly when no selection is needed.
| Property | Type | Notes |
|---|---|---|
ItemsSource | IEnumerable | Bound collection |
ItemTemplate | DataTemplate | Template for each item |
ItemsPanel | ItemsPanelTemplate | Layout panel (default: StackPanel) |
ItemContainerTheme | ControlTheme | Style for each container |
<!-- Simple read-only list -->
<ItemsControl ItemsSource="{Binding Tags}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:TagVm">
<Border Background="#E3F2FD" CornerRadius="4" Padding="8,4" Margin="0,0,4,4">
<TextBlock Text="{Binding Name}" FontSize="12"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<!-- Horizontal wrapping layout -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
ListBox
Extends ItemsControl with selection. Virtualizes items by default.
| Property | Type | Notes |
|---|---|---|
SelectedItem | object | TwoWay by default |
SelectedItems | IList | Multiple selection (requires SelectionMode flag) |
SelectedIndex | int | Zero-based index |
SelectionMode | SelectionMode | Single, Multiple, Toggle, AlwaysSelected |
Scroll | ScrollViewer | Access the internal scroll viewer |
12.0+ behavior: touch/pen selection happens on pointer release (swipe/scroll no longer selects).
ListBoxItemandTreeViewItemhandle selection themselves — to customize, overrideShouldTriggerSelection/UpdateSelectionFromEventrather than intercepting at theListBox/TreeViewlevel.UpdateSelection/UpdateSelectionFromEventSourceare obsolete.
<ListBox ItemsSource="{Binding People}"
SelectedItem="{Binding SelectedPerson}"
SelectionMode="Single">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:PersonVm">
<StackPanel Margin="4">
<TextBlock Text="{Binding FullName}" FontWeight="SemiBold"/>
<TextBlock Text="{Binding Email}" FontSize="12" Foreground="Gray"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!-- Multi-select -->
<ListBox ItemsSource="{Binding Files}"
Read the complete source ↗