Avalonia UI Framework - Orchestration Hub
Modular guidance for cross-platform desktop and mobile development using Avalonia, a WPF-inspired XAML-based framework for .NET.
Quick Reference: When to Load Which Resource
| Task/Goal |
Load Resource |
| MVVM patterns, data binding, dependency injection, value converters |
resources/mvvm-databinding.md |
| UI controls reference (layouts, inputs, collections, menus) |
resources/controls-reference.md |
| Custom controls, advanced layouts, performance optimization, virtualization |
resources/custom-controls-advanced.md |
| Styling, themes, animations, control templates |
resources/styling-guide.md |
| Reactive patterns, commands, observables, animations |
resources/reactive-animations.md |
| Windows, macOS, Linux, iOS, Android implementation details |
resources/platform-specific.md |
Framework Overview
Avalonia is a cross-platform XAML framework supporting:
- Platforms: Windows, macOS, Linux, iOS, Android, WebAssembly
- Architecture: MVVM with ReactiveUI support
- Styling: CSS-like selectors with Fluent/Simple themes
- Features: Data binding, reactive commands, observable collections, custom controls
- Modern .NET: .NET 6+ and .NET Standard 2.0
Standard Project Structure
MyAvaloniaApp/
├── MyAvaloniaApp/ # Shared code
│ ├── App.axaml
│ ├── Views/ # XAML views
│ ├── ViewModels/ # Business logic + state
│ ├── Models/ # Data models
│ ├── Services/ # Application services
│ ├── Converters/ # Value converters
│ ├── Assets/ # Images, fonts
│ └── Styles/ # Style resources
├── MyAvaloniaApp.Desktop/ # Desktop-specific (Win/Mac/Linux)
├── MyAvaloniaApp.Android/ # Android-specific (optional)
├── MyAvaloniaApp.iOS/ # iOS-specific (optional)
└── MyAvaloniaApp.Browser/ # WebAssembly (optional)
Getting Started
Minimal Setup
// Program.cs
public static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
<!-- App.axaml -->
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApp.App">
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
<!-- Views/MainWindow.axaml -->
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApp.Views.MainWindow"
Title="My Application"
Width="800"
Height="600">
<StackPanel Padding="20" Spacing="10">
<TextBlock Text="Hello, Avalonia!" FontSize="24" FontWeight="Bold" />
</StackPanel>
</Window>
Core Patterns
MVVM Architecture Pattern
- View (XAML): UI presentation with data bindings
- ViewModel (C#): State management and commands
- Model (C#): Business logic and data access
- Service: Cross-cutting concerns (DI/IoC)
Load resources/mvvm-databinding.md for:
- ViewModel base classes
- Data binding modes and paths
- Multi-binding and converters
- Dependency injection setup
- Design-time data
Reactive Programming Pattern
Leverage ReactiveUI for event-driven UI updates:
this.WhenAnyValue(x => x.SearchText)
.Debounce(TimeSpan.FromMilliseconds(300))
.Subscribe(text => PerformSearch(text));
Load resources/reactive-animations.md for:
- Reactive properties and commands
- Observable sequences
- Animations and transitions
- Performance optimization
Platform-Adaptive Pattern
Design once, adapt per platform:
<OnPlatform Default="16">
<On Options="Windows" Content="14" />
<On Options="macOS" Content="15" />
</OnPlatform>
Load resources/platform-specific.md for:
- Runtime platform detection
- Platform-specific services
- Conditional UI rendering
- Native dialogs and features
Navigation by Task
"I need to build a form with validation"
- Load
resources/mvvm-databinding.md → Implement ViewModel with property validation
- Load
resources/controls-reference.md → Find TextBox, ComboBox, Button controls
- Load
resources/reactive-animations.md → Add debounced validation with observables
"I'm seeing poor performance with large lists"
- Load
resources/custom-controls-advanced.md → Enable virtualization
- Load
resources/mvvm-databinding.md → Use compiled bindings
- Load
resources/reactive-animations.md → Debounce/throttle updates
"I need platform-specific behavior"
- Load
resources/platform-specific.md → Implement service interfaces
- Load
resources/mvvm-databinding.md → Register platform implementations via DI
- Platform-specific
resources/ → Implement per-platform project
"I want custom styling and animations"
- Load
resources/styling-guide.md → Define styles and themes
- Load
resources/reactive-animations.md → Add animations to styles
- Load
resources/custom-controls-advanced.md → Custom control templates
"I'm building a complex control"
- Load
resources/custom-controls-advanced.md → TemplatedControl or UserControl pattern
- Load
resources/mvvm-databinding.md → Attached properties and data binding
- Load
resources/styling-guide.md → Control templates and styling
Resource Organization
mvvm-databinding.md (Primary)
- Architecture overview
- ViewModel patterns with ReactiveUI
- Binding modes and syntax
- Value converters
- Collections and list binding
- Design-time data
- Master-detail and tab patterns
controls-reference.md (Primary)
- Layout controls (Grid, StackPanel, DockPanel, etc.)
- Input controls (TextBox, Button, CheckBox, ComboBox, etc.)
- Display controls (TextBlock, Image, ProgressBar, etc.)
- Collection controls (ListBox, DataGrid, TreeView, etc.)
- Navigation (Menu, TabControl, SplitView, etc.)
- Shapes and drawing
styling-guide.md (Primary)
- CSS-like selectors (type, class, pseudo-classes)
- Resource dictionaries and themes
- Control templates
- Data templates
- Animations and transitions
- Easing functions
- Theme variants (light/dark)
reactive-animations.md (Advanced)
- ReactiveUI integration
- Reactive properties
- Reactive commands (sync and async)
- Observable sequences
- Filtering, transformation, combining
- Programmatic animations
- Common patterns (search, validation, auto-complete)
custom-controls-advanced.md (Advanced)
- Custom TemplatedControl creation
- User control composition
- Advanced layouts
- Virtualization
- Performance optimization
- Render transforms
- Graphics and drawing
platform-specific.md (Advanced)
- Runtime platform detection
- Multi-project structure
- Service abstractions
- Platform-specific implementations
- Window management per platform
- File system access
- Native features (Windows DLL, macOS Cocoa, etc.)
Common Workflows
Build a Desktop App (Windows/macOS/Linux)
1. → Setup: Standard project structure + FluentTheme
2. → Create Views and ViewModels following MVVM
3. → Use controls-reference for UI layouts
4. → Add styles with styling-guide
5. → Implement services with DI (mvvm-databinding)
6. → Add animations with reactive-animations
7. → Test on each platform with platform-specific guidance
Build a Cross-Platform Mobile+Desktop App
1. → Create shared project + platform-specific projects
2. → Define service interfaces in shared code (mvvm-databinding)
3. → Implement services per platform (platform-specific)
4. → Use OnPlatform for adaptive UI
5. → Register platform implementations via DI
6. → Test thoroughly on each target (iOS/Android/Windows/Mac)
Add Real-Time Search
1. → Create SearchViewModel (mvvm-databinding)
2. → Use ObservableCollection for results (mvvm-databinding)
3. → Implement with reactive search pattern (reactive-animations)
4. → Debounce input to reduce API calls
5. → Display with ListBox (controls-reference)
6. → Style with appropriate CSS selectors (styling-guide)
Build Complex Data-Driven UI
1. → Design ViewModel hierarchy (mvvm-databinding)
2. → Create master-detail view (mvvm-databinding)
3. → Use DataGrid for tabular data (controls-reference)
4. → Add sorting/filtering with observables (reactive-animations)
5. → Optimize with virtualization (custom-controls-advanced)
6. → Add custom controls if needed (custom-controls-advanced)
Best Practices Summary
Architecture
- Maintain strict MVVM separation of concerns
- Use dependency injection for testability
- Keep business logic in ViewModels, not Views
Performance
- Enable compiled bindings with
x:DataType
- Virtualize large collections
- Debounce rapid updates
Styling
- Use resource dictionaries for consistency
- Support light and dark themes
- Test styles on all target platforms
Reactive Patterns
- Use observables for event-driven updates
- Debounce/throttle input-triggered operations
- Always handle ThrownExceptions on commands
Testing
- Unit test ViewModels in isolation
- Use Avalonia.Headless for UI testing
- Provide design-time DataContext in XAML
Cross-Platform Deployment
- Windows: ClickOnce, MSI, portable exe
- macOS: DMG, homebrew
- Linux: AppImage, snap, flatpak
- Mobile: Apple App Store, Google Play Store
- Web: Static hosting (WASM runtime required)
Refer to resources/platform-specific.md for platform-specific build and deployment guidance.
Navigation: Choose a resource above based on your task. Each resource is self-contained with comprehensive examples and best practices.
1---2name: avalonia-23description: Expert guidance for developing cross-platform desktop applications with Avalonia UI framework. Use when building, debugging, or optimizing Avalonia apps including MVVM architecture, XAML design, data binding, styling, theming, custom controls, and cross-platform deployment for Windows, macOS, Linux, iOS, Android, and WebAssembly.4---5
6# Avalonia UI Framework - Orchestration Hub
7
8Modular guidance for cross-platform desktop and mobile development using Avalonia, a WPF-inspired XAML-based framework for .NET.
9
10## Quick Reference: When to Load Which Resource
11
12| Task/Goal | Load Resource |
13|-----------|---------------|
14| MVVM patterns, data binding, dependency injection, value converters | `resources/mvvm-databinding.md` |
15| UI controls reference (layouts, inputs, collections, menus) | `resources/controls-reference.md` |
16| Custom controls, advanced layouts, performance optimization, virtualization | `resources/custom-controls-advanced.md` |
17| Styling, themes, animations, control templates | `resources/styling-guide.md` |
18| Reactive patterns, commands, observables, animations | `resources/reactive-animations.md` |
19| Windows, macOS, Linux, iOS, Android implementation details | `resources/platform-specific.md` |
20
21## Framework Overview
22
23**Avalonia** is a cross-platform XAML framework supporting:
24- **Platforms**: Windows, macOS, Linux, iOS, Android, WebAssembly
25- **Architecture**: MVVM with ReactiveUI support
26- **Styling**: CSS-like selectors with Fluent/Simple themes
27- **Features**: Data binding, reactive commands, observable collections, custom controls
28- **Modern .NET**: .NET 6+ and .NET Standard 2.0
29
30### Standard Project Structure
31
32```
33MyAvaloniaApp/
34├── MyAvaloniaApp/ # Shared code
35│ ├── App.axaml
36│ ├── Views/ # XAML views
37│ ├── ViewModels/ # Business logic + state
38│ ├── Models/ # Data models
39│ ├── Services/ # Application services
40│ ├── Converters/ # Value converters
41│ ├── Assets/ # Images, fonts
42│ └── Styles/ # Style resources
43├── MyAvaloniaApp.Desktop/ # Desktop-specific (Win/Mac/Linux)
44├── MyAvaloniaApp.Android/ # Android-specific (optional)
45├── MyAvaloniaApp.iOS/ # iOS-specific (optional)
46└── MyAvaloniaApp.Browser/ # WebAssembly (optional)
47```
48
49## Getting Started
50
51### Minimal Setup
52
53```csharp
54// Program.cs
55public static void Main(string[] args)
56{
57 BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
58}
59
60public static AppBuilder BuildAvaloniaApp() =>
61 AppBuilder.Configure<App>()
62 .UsePlatformDetect()
63 .LogToTrace();
64```
65
66```xml
67<!-- App.axaml -->
68<Application xmlns="https://github.com/avaloniaui"
69 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
70 x:Class="MyApp.App">
71 <Application.Styles>
72 <FluentTheme />
73 </Application.Styles>
74</Application>
75```
76
77```xml
78<!-- Views/MainWindow.axaml -->
79<Window xmlns="https://github.com/avaloniaui"
80 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
81 x:Class="MyApp.Views.MainWindow"
82 Title="My Application"
83 Width="800"
84 Height="600">
85 <StackPanel Padding="20" Spacing="10">
86 <TextBlock Text="Hello, Avalonia!" FontSize="24" FontWeight="Bold" />
87 </StackPanel>
88</Window>
89```
90
91## Core Patterns
92
93### MVVM Architecture Pattern
94
951. **View** (XAML): UI presentation with data bindings
962. **ViewModel** (C#): State management and commands
973. **Model** (C#): Business logic and data access
984. **Service**: Cross-cutting concerns (DI/IoC)
99
100**Load** `resources/mvvm-databinding.md` for:
101- ViewModel base classes
102- Data binding modes and paths
103- Multi-binding and converters
104- Dependency injection setup
105- Design-time data
106
107### Reactive Programming Pattern
108
109Leverage ReactiveUI for event-driven UI updates:
110
111```csharp
112this.WhenAnyValue(x => x.SearchText)
113 .Debounce(TimeSpan.FromMilliseconds(300))
114 .Subscribe(text => PerformSearch(text));
115```
116
117**Load** `resources/reactive-animations.md` for:
118- Reactive properties and commands
119- Observable sequences
120- Animations and transitions
121- Performance optimization
122
123### Platform-Adaptive Pattern
124
125Design once, adapt per platform:
126
127```xml
128<OnPlatform Default="16">
129 <On Options="Windows" Content="14" />
130 <On Options="macOS" Content="15" />
131</OnPlatform>
132```
133
134**Load** `resources/platform-specific.md` for:
135- Runtime platform detection
136- Platform-specific services
137- Conditional UI rendering
138- Native dialogs and features
139
140## Navigation by Task
141
142### "I need to build a form with validation"
143
1441. Load `resources/mvvm-databinding.md` → Implement ViewModel with property validation
1452. Load `resources/controls-reference.md` → Find TextBox, ComboBox, Button controls
1463. Load `resources/reactive-animations.md` → Add debounced validation with observables
147
148### "I'm seeing poor performance with large lists"
149
1501. Load `resources/custom-controls-advanced.md` → Enable virtualization
1512. Load `resources/mvvm-databinding.md` → Use compiled bindings
1523. Load `resources/reactive-animations.md` → Debounce/throttle updates
153
154### "I need platform-specific behavior"
155
1561. Load `resources/platform-specific.md` → Implement service interfaces
1572. Load `resources/mvvm-databinding.md` → Register platform implementations via DI
1583. Platform-specific `resources/` → Implement per-platform project
159
160### "I want custom styling and animations"
161
1621. Load `resources/styling-guide.md` → Define styles and themes
1632. Load `resources/reactive-animations.md` → Add animations to styles
1643. Load `resources/custom-controls-advanced.md` → Custom control templates
165
166### "I'm building a complex control"
167
1681. Load `resources/custom-controls-advanced.md` → TemplatedControl or UserControl pattern
1692. Load `resources/mvvm-databinding.md` → Attached properties and data binding
1703. Load `resources/styling-guide.md` → Control templates and styling
171
172## Resource Organization
173
174### `mvvm-databinding.md` (Primary)
175- Architecture overview
176- ViewModel patterns with ReactiveUI
177- Binding modes and syntax
178- Value converters
179- Collections and list binding
180- Design-time data
181- Master-detail and tab patterns
182
183### `controls-reference.md` (Primary)
184- Layout controls (Grid, StackPanel, DockPanel, etc.)
185- Input controls (TextBox, Button, CheckBox, ComboBox, etc.)
186- Display controls (TextBlock, Image, ProgressBar, etc.)
187- Collection controls (ListBox, DataGrid, TreeView, etc.)
188- Navigation (Menu, TabControl, SplitView, etc.)
189- Shapes and drawing
190
191### `styling-guide.md` (Primary)
192- CSS-like selectors (type, class, pseudo-classes)
193- Resource dictionaries and themes
194- Control templates
195- Data templates
196- Animations and transitions
197- Easing functions
198- Theme variants (light/dark)
199
200### `reactive-animations.md` (Advanced)
201- ReactiveUI integration
202- Reactive properties
203- Reactive commands (sync and async)
204- Observable sequences
205- Filtering, transformation, combining
206- Programmatic animations
207- Common patterns (search, validation, auto-complete)
208
209### `custom-controls-advanced.md` (Advanced)
210- Custom TemplatedControl creation
211- User control composition
212- Advanced layouts
213- Virtualization
214- Performance optimization
215- Render transforms
216- Graphics and drawing
217
218### `platform-specific.md` (Advanced)
219- Runtime platform detection
220- Multi-project structure
221- Service abstractions
222- Platform-specific implementations
223- Window management per platform
224- File system access
225- Native features (Windows DLL, macOS Cocoa, etc.)
226
227## Common Workflows
228
229### Build a Desktop App (Windows/macOS/Linux)
230
231```
2321. → Setup: Standard project structure + FluentTheme
2332. → Create Views and ViewModels following MVVM
2343. → Use controls-reference for UI layouts
2354. → Add styles with styling-guide
2365. → Implement services with DI (mvvm-databinding)
2376. → Add animations with reactive-animations
2387. → Test on each platform with platform-specific guidance
239```
240
241### Build a Cross-Platform Mobile+Desktop App
242
243```
2441. → Create shared project + platform-specific projects
2452. → Define service interfaces in shared code (mvvm-databinding)
2463. → Implement services per platform (platform-specific)
2474. → Use OnPlatform for adaptive UI
2485. → Register platform implementations via DI
2496. → Test thoroughly on each target (iOS/Android/Windows/Mac)
250```
251
252### Add Real-Time Search
253
254```
2551. → Create SearchViewModel (mvvm-databinding)
2562. → Use ObservableCollection for results (mvvm-databinding)
2573. → Implement with reactive search pattern (reactive-animations)
2584. → Debounce input to reduce API calls
2595. → Display with ListBox (controls-reference)
2606. → Style with appropriate CSS selectors (styling-guide)
261```
262
263### Build Complex Data-Driven UI
264
265```
2661. → Design ViewModel hierarchy (mvvm-databinding)
2672. → Create master-detail view (mvvm-databinding)
2683. → Use DataGrid for tabular data (controls-reference)
2694. → Add sorting/filtering with observables (reactive-animations)
2705. → Optimize with virtualization (custom-controls-advanced)
2716. → Add custom controls if needed (custom-controls-advanced)
272```
273
274## Best Practices Summary
275
276**Architecture**
277- Maintain strict MVVM separation of concerns
278- Use dependency injection for testability
279- Keep business logic in ViewModels, not Views
280
281**Performance**
282- Enable compiled bindings with `x:DataType`
283- Virtualize large collections
284- Debounce rapid updates
285
286**Styling**
287- Use resource dictionaries for consistency
288- Support light and dark themes
289- Test styles on all target platforms
290
291**Reactive Patterns**
292- Use observables for event-driven updates
293- Debounce/throttle input-triggered operations
294- Always handle ThrownExceptions on commands
295
296**Testing**
297- Unit test ViewModels in isolation
298- Use Avalonia.Headless for UI testing
299- Provide design-time DataContext in XAML
300
301## Cross-Platform Deployment
302
303- **Windows**: ClickOnce, MSI, portable exe
304- **macOS**: DMG, homebrew
305- **Linux**: AppImage, snap, flatpak
306- **Mobile**: Apple App Store, Google Play Store
307- **Web**: Static hosting (WASM runtime required)
308
309Refer to `resources/platform-specific.md` for platform-specific build and deployment guidance.
310
311---
312
313**Navigation**: Choose a resource above based on your task. Each resource is self-contained with comprehensive examples and best practices.