Overview
Avalonia UI is considered by many to be the spiritual successor to WPF. While similar to WPF, it isn’t a 1:1 copy, and you’ll find plenty of improvements. This guide will help you understand the key differences and similarities to successfully migrate your WPF applications to Avalonia.For those seeking a cross-platform WPF with minimal code changes, Avalonia XPF is a commercial product that enables WPF applications to run on macOS and Linux.
Key Similarities
Avalonia shares many core concepts with WPF:- XAML-based UI: Both use declarative XAML markup for defining user interfaces
- Data binding: Full support for
INotifyPropertyChanged, data binding, and MVVM patterns - Dependency properties: Similar property system with attached properties
- Styling system: Resources, styles, and templates work similarly
- Controls library: Many familiar controls with similar APIs
- Routed events: Event bubbling and tunneling mechanisms
Major Differences
File Extensions
Avalonia uses.axaml files instead of .xaml to differentiate from WPF:
Namespace Declarations
WPF:Application Entry Point
The application startup differs between WPF and Avalonia. WPF Program.cs:The
BuildAvaloniaApp() method is also used by the IDE previewer infrastructure.Property Changes
Some properties have different names or behaviors:| WPF | Avalonia | Notes |
|---|---|---|
Window.AllowsTransparency | Window.TransparencyLevelHint | Enhanced transparency control |
FrameworkElement.DataContext | StyledElement.DataContext | Same concept, different base class |
Panel.Children | Panel.Children | Same API |
TextBlock.Inlines | TextBlock.Inlines | Same API |
Migration Steps
Set up your Avalonia project
Create a new Avalonia application using the templates:Or use the Visual Studio Extension or JetBrains Rider which has built-in Avalonia support.
Update XAML files
- Rename
.xamlfiles to.axaml(optional but recommended) - Update the XML namespace:
- Update the schema location for IntelliSense:
Control Mapping
Most WPF controls have direct equivalents in Avalonia:| WPF Control | Avalonia Control | Differences |
|---|---|---|
Button | Button | Same API |
TextBox | TextBox | Same API |
ComboBox | ComboBox | Same API |
DataGrid | DataGrid | Requires Avalonia.Controls.DataGrid package |
TreeView | TreeView | Same API |
Menu | Menu | Same API |
ContextMenu | ContextMenu | Same API |
Window | Window | Enhanced for cross-platform |
Styling Differences
WPF Styles
Avalonia Styles
Data Binding
Avalonia supports the same binding syntax as WPF:Platform-Specific Features
Avalonia provides cross-platform abstractions while allowing platform-specific customization:Designer Support
Avalonia provides designer support similar to WPF:- Visual Studio: Install the Avalonia for Visual Studio extension
- JetBrains Rider: Built-in support with XAML previewer via the AvaloniaRider plugin
- VS Code: Use the Avalonia extensions for syntax highlighting and previewing
Porting Third-Party Code
When porting code from WPF or other MIT-compatible sources, include appropriate license headers:Common Migration Issues
Issue: DependencyProperty not found
Issue: DependencyProperty not found
Avalonia uses
StyledProperty and DirectProperty instead of DependencyProperty. Convert your properties using Avalonia’s property system.Issue: ResourceDictionary location
Issue: ResourceDictionary location
Avalonia uses
avares:// URIs for resources:Issue: Missing controls
Issue: Missing controls
Some WPF controls may not have direct equivalents. Check the Avalonia.Controls namespace or community packages for alternatives.
Additional Resources
Official Documentation
Complete Avalonia documentation and tutorials
Awesome Avalonia
Community-curated list of tools and resources
Samples
Official sample applications and code examples
Community
Join the Avalonia Telegram community
Next Steps
After migrating your application:- Test on multiple platforms (Windows, macOS, Linux)
- Review and update any platform-specific code
- Optimize for cross-platform performance
- Consider using Avalonia’s enhanced features like better styling and theming