avalonia-xaml
Skill50 starsChanged 9 days agoMITView on GitHub
Use when writing or reviewing Avalonia XAML markup, .axaml files, XML namespaces, code-behind, markup extensions, runtime XAML loading, or building UI without XAML in code.
In this repository23 other files it gives its agents.
- avalonia-app-developmentSkill
- avalonia-controlsSkill
- avalonia-custom-controlsSkill
- avalonia-data-bindingSkill
- avalonia-data-templatesSkill
- avalonia-deploymentSkill
- avalonia-eventsSkill
- avalonia-graphics-animationSkill
- avalonia-input-interactionSkill
- avalonia-interop-renderingSkill
- avalonia-layoutSkill
- avalonia-mobileSkill
- avalonia-mvvmSkill
- avalonia-performanceSkill
- avalonia-pro-maxSkill
- avalonia-property-systemSkill
- avalonia-servicesSkill
- avalonia-stylingSkill
- avalonia-testingSkill
- avalonia-threadingSkill
- avalonia-versionsSkill
- avalonia-wpf-migrationSkill
- avaloniaSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Every .axaml file requires the Avalonia root namespace and language namespace:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Avalonia XAML
Overview
Avalonia uses .axaml extension (not .xaml) to avoid Visual Studio WPF tooling conflicts. XAML is optional; full code-only UI is supported. (12.0+) compiled bindings are ON by default (AvaloniaUseCompiledBindingsByDefault=true): {Binding} maps to CompiledBinding, so x:DataType is required wherever bindings are used. In 11.x compiled bindings are opt-in ({CompiledBinding} / x:CompileBindings="True"). Escape hatch: {ReflectionBinding Path} or x:CompileBindings="False".
File Structure
Every .axaml file requires the Avalonia root namespace and language namespace:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:Class="MyApp.MainWindow"
x:DataType="vm:MainWindowViewModel"
Title="My App"
Width="800" Height="450">
<TextBlock Text="{Binding Greeting}" />
</Window>Corresponding code-behind:
// MainWindow.axaml.cs
using Avalonia.Controls;
namespace MyApp;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}XML Namespaces
Namespace Syntax
| Syntax | Use case | Example |
using: | Same solution assemblies (preferred) | xmlns:vm="using:MyApp.ViewModels" |
clr-namespace: | External assemblies (requires ;assembly=) | xmlns:ctrl="clr-namespace:MyLib.Controls;assembly=MyLib" |
| URI | Framework namespaces | xmlns="https://github.com/avaloniaui" |
Common Namespaces
| Prefix | URI / Syntax | Purpose |
| (default) | https://github.com/avaloniaui | All Avalonia controls |
x: | http://schemas.microsoft.com/winfx/2006/xaml | XAML language features |
vm: | using:MyApp.ViewModels | ViewModel types |
conv: | using:MyApp.Converters | Converter classes |
sys: | using:System | System types (Math, String, etc.) |
Markup Extensions
| Extension | Purpose | Example |
{Binding} | Compiled binding in 12.0+ (needs x:DataType); reflection binding in 11.x | Text="{Binding Name}" |
{CompiledBinding} | Explicit compile-time checked binding (all versions) | Text="{CompiledBinding Name}" |
{ReflectionBinding} | Runtime reflection binding; opt-out when no x:DataType (12.0+; 11.x: use {Binding}) | Text="{ReflectionBinding Name}" |
{StaticResource} | One-time resource lookup | Fill="{StaticResource AccentBrush}" |
{DynamicResource} | Live resource lookup (updates on change) | Background="{DynamicResource SystemControlBackground}" |
{x:Static} | Static field/property | Value="{x:Static sys:Math.PI}" |
{x:Type} | Type reference | TargetType="{x:Type Button}" |
{x:Null} | Null literal | Tag="{x:Null}" |
{OnPlatform} | Per-platform value | FontSize="{OnPlatform 12, macOS=14}" |
{OnFormFactor} | Per-form-factor value | Width="{OnFormFactor 200, Mobile=100}" |
x: Attributes
| Attribute | Purpose | Notes |
x:Class | Links AXAML to code-behind partial class | Must match namespace + class name exactly |
x:Name | Names control for code-behind access | Generates a typed field in partial class |
x:Key | Resource dictionary key | Required for resources in <ResourceDictionary> |
x:DataType | Compiled binding root type | Required on root or DataTemplate when using compiled bindings |
x:CompileBindings | Enable/disable compiled bindings per scope | x:CompileBindings="False" to opt out |
ExperimentalAttribute (12.0+) | XAML honors [Experimental] on types/members: using them needs the diagnostic suppressed (<NoWarn>) |
Code-Behind Pattern
// MyView.axaml.cs
using Avalonia.Controls;
namespace MyApp.Views;
public partial class MyView : UserControl
{
public MyView()
{
InitializeComponent();
}
// Access named controls via generated fields
private void OnButtonClick(object sender, RoutedEventArgs e)
{
// myButton is generated from x:Name="myButton" in AXAML
myButton.IsEnabled = false;
}
}<!-- MyView.axaml -->
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApp.Views.MyView">
<Button x:Name="myButton"
Content="Click Me"
Click="OnButtonClick" />
</UserControl>Code-Only UI (No XAML)
Preferred for: dynamic control creation, headless testing, generated UIs.
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
var window = new Window
{
Title = "Code Only",
Width = 400,
Height = 300,
Content = new StackPanel
{
Spacing = 8,
Margin = new Thickness(16),
Children =
{
new TextBlock { Text = "Hello, Avalonia!" },
new Button
{
Content = "Click Me",
HorizontalAlignment = HorizontalAlignment.Left
}
}
}
};Bindings in code:
var textBox = new TextBox { DataContext = viewModel };
// (12.0+) explicit types; `new Binding(...)` is a compat alias of ReflectionBinding
textBox.Bind(TextBox.TextProperty, new ReflectionBinding(nameof(MainViewModel.Name)));
textBox.Bind(TextBox.TextProperty, CompiledBinding.Create((MainViewModel vm) => vm.Name)); // (12.0+) AOT/trim safe
// (11.x)
textBox.Bind(TextBox.TextProperty, new Binding("Name"));Gesture Events (12.0+)
Gesture attached events live directly on InputElement — drop the Gestures. prefix (Gestures is no longer public):
<Border Pinch="OnPinch" ScrollGesture="OnScroll" Tapped="OnTapped" />
<!-- (11.x) <Border Gestures.Pinch="OnPinch" Gestures.ScrollGesture="OnScroll" /> -->Resource Dictionaries
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://MyApp/Assets/Colors.axaml"/>
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="BrandBrush" Color="#5B4FCF"/>
</ResourceDictionary>
</Application.Resources><!-- Colors.axaml -->
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="BrandColor">#5B4FCF</Color>
</ResourceDictionary>Runtime XAML for Previewers and Editors
For runtime-loaded documents, relative includes, existing root instances, diagnostics, and source locations, read references/runtime-xaml.md. It covers Avalonia 12.1 and 11.3; normal application views should keep the compiled InitializeComponent() path.
Common Mistakes
| Mistake | Fix |
Using .xaml extension | Rename to .axaml |
Missing xmlns="https://github.com/avaloniaui" | Add as first attribute on root element |
clr-namespace: without ;assembly= for external lib | xmlns:x="clr-namespace:MyLib;assembly=MyLib" |
Compiled binding error: "Cannot resolve symbol" / {Binding} fails to compile after moving to 12 | Add x:DataType="vm:MyViewModel" to root or DataTemplate, or use {ReflectionBinding} |
Gestures.Pinch="..." in 12.x | Pinch="..." (12.0+) |
x:Name field not accessible in code-behind | Ensure file is .axaml and InitializeComponent() is called |
{StaticResource} not found at runtime | Resource must be defined before use in document order |
{DynamicResource} for performance-sensitive paths | Use {StaticResource} when resource never changes |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

