Skip to main content

WPF to Avalonia cheat sheet

A quick reference for WPF developers transitioning to Avalonia. Each entry shows the WPF concept and its Avalonia equivalent.

XAML namespace​

WPFAvalonia
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Same
xmlns:local="clr-namespace:MyApp"xmlns:local="using:MyApp" (preferred) or clr-namespace:

Property system​

WPFAvaloniaNotes
DependencyPropertyStyledPropertySupports styling, animation, inheritance
DependencyProperty (perf-critical)DirectPropertyFaster but no styling/animation
DependencyProperty.Register()AvaloniaProperty.Register<TOwner, TValue>()Generic registration
DependencyProperty.RegisterAttached()AvaloniaProperty.RegisterAttached<TValue>()Attached properties
PropertyMetadataStyledPropertyMetadata<T>Type-safe metadata
CoerceValueCallbackCoerceValueCallback via metadataSame concept
PropertyChanged callback in metadatapropertyChanged callback in RegisterPassed directly

Styling​

WPFAvaloniaNotes
<Style TargetType="Button"><Style Selector="Button">CSS-like selectors
Style.TriggersPseudo-classes (:pointerover, :pressed)No triggers in Avalonia
DataTriggerBindings + pseudo-classes or convertersSee below
EventTriggerAnimations on pseudo-classes
VisualStateManagerPseudo-classes:pointerover, :pressed, :disabled, :checked
BasedOn="{StaticResource ...}"Not needed; selectors compose
Style x:Key="..."Style classes: <Style Selector="Button.primary">
Style="{StaticResource ButtonStyle}"Classes="primary"
ControlTemplate.TriggersPseudo-class selectors
TemplateBindingTemplateBindingSame concept, but Avalonia supports Mode=TwoWay
{RelativeSource TemplatedParent}{TemplateBinding} or $parent[ControlType]

DataTrigger equivalent​

WPF:

<DataTrigger Binding="{Binding IsActive}" Value="True">
<Setter Property="Background" Value="Green" />
</DataTrigger>

Avalonia (use a converter or custom pseudo-class):

<Style Selector="Border.status">
<Setter Property="Background" Value="Red" />
</Style>
<Style Selector="Border.status[(vm:MyViewModel.IsActive)]">
<Setter Property="Background" Value="Green" />
</Style>

Or with a binding converter:

<Border Background="{Binding IsActive, Converter={StaticResource BoolToColorConverter}}" />

Data binding​

WPFAvaloniaNotes
{Binding Path}{Binding Path}Same syntax
{Binding Path, Mode=TwoWay}{Binding Path, Mode=TwoWay}Same
{Binding RelativeSource={RelativeSource Self}}{Binding $self.Property}Shorthand syntax
{Binding RelativeSource={RelativeSource AncestorType=Grid}}{Binding $parent[Grid].Property}
{Binding RelativeSource={RelativeSource TemplatedParent}}{TemplateBinding Property}
{Binding ElementName=myControl, Path=Text}{Binding #myControl.Text}#name syntax
CompiledBinding{CompiledBinding} or x:CompileBindings="True"Compile-time validation
MultiBindingMultiBindingSame concept
IValueConverterIValueConverterSame interface
IMultiValueConverterIMultiValueConverterSame interface
FallbackValueFallbackValueSame
TargetNullValueTargetNullValueSame
StringFormatStringFormatSame
UpdateSourceTriggerNot needed; defaults are sensibleTextBox updates on text change

Controls​

WPFAvaloniaNotes
WindowWindowSame
UserControlUserControlSame
ButtonButtonSame
TextBlockTextBlockSame
TextBoxTextBoxSame
CheckBoxCheckBoxSame
RadioButtonRadioButtonSame
ComboBoxComboBoxSame
ListBoxListBoxSame
ListViewListBoxUse ListBox with ItemTemplate
TreeViewTreeViewSame
DataGridDataGrid (NuGet package)Separate package
TabControlTabControlSame
ExpanderExpanderSame
SliderSliderSame
ProgressBarProgressBarSame
ToolTipToolTipAttached property: ToolTip.Tip
StatusBarNo direct equivalentUse a styled panel
MenuMenuSame
ContextMenuContextMenuSame
PopupPopupSame
ScrollViewerScrollViewerSame
ImageImageSame
BorderBorderSame; supports BoxShadow
ViewboxViewboxSame
ContentControlContentControlSame
ItemsControlItemsControlSame
StackPanelStackPanelSame
GridGridSame; shorthand ColumnDefinitions="Auto,*"
DockPanelDockPanelSame
WrapPanelWrapPanelSame
CanvasCanvasSame
UniformGridUniformGridSame
GroupBoxGroupBoxSame
RichTextBoxNo built-in equivalentUse a third-party editor

Layout​

WPFAvaloniaNotes
Grid.RowDefinitions="Auto,*"Same shorthandBoth support inline syntax
DockPanel.LastChildFillDockPanel.LastChildFillSame
HorizontalAlignmentHorizontalAlignmentSame
VerticalAlignmentVerticalAlignmentSame
Margin="10,5"Margin="10,5"Same
SharedSizeGroupSharedSizeGroupSame
Visibility (Visible/Collapsed/Hidden)IsVisible (bool)IsVisible="False" equals WPF Collapsed (removed from layout). For WPF Hidden (invisible but still occupies space), use Opacity="0" instead.

Resources​

WPFAvaloniaNotes
StaticResourceStaticResourceSame (resolved once)
DynamicResourceDynamicResourceSame (tracks changes)
MergedDictionariesMergedDictionariesSame
ResourceDictionaryResourceDictionarySame
ThemeDictionariesResourceDictionary.ThemeDictionariesLight/Dark variants

Events​

WPFAvaloniaNotes
RoutedEvent (Bubble)RoutedEvent (Bubble)Same
RoutedEvent (Tunnel)RoutedEvent (Tunnel)Same
Preview* eventsTunnel routing strategyUse AddHandler with RoutingStrategies.Tunnel
EventManager.RegisterRoutedEventRoutedEvent.Register<T, TArgs>Generic registration
e.Handled = truee.Handled = trueSame
AddHandler(event, handler, handledEventsToo)Same signatureSame
Class handlersEvent.AddClassHandler<T>()Same concept

Commands​

WPFAvaloniaNotes
ICommandICommandSame interface
RoutedCommandNo built-in equivalentUse ICommand implementations
CommandBindingNo equivalentBind commands directly
InputBinding / KeyBindingKeyBindingSame concept
RelayCommand (MVVM toolkit)RelayCommand (CommunityToolkit.Mvvm)Same library works

Templates​

WPFAvaloniaNotes
DataTemplateDataTemplateSame
HierarchicalDataTemplateTreeDataTemplateDifferent name
ControlTemplateControlTemplateSame
DataTemplateSelectorDataTemplate with DataTypeUse DataType matching
ContentPresenterContentPresenterSame
ItemsPresenterItemsPresenterSame
PART_ naming conventionPART_ naming conventionSame

Threading​

WPFAvaloniaNotes
Dispatcher.Invoke()Dispatcher.UIThread.InvokeAsync()Async by default
Dispatcher.BeginInvoke()Dispatcher.UIThread.Post()Fire-and-forget
Dispatcher.CurrentDispatcherDispatcher.CurrentDispatcherSame API
Dispatcher.FromThread()Dispatcher.FromThread()Same API
DependencyObject.DispatcherAvaloniaObject.DispatcherPer-object dispatcher
Dispatcher.CheckAccess()Dispatcher.UIThread.CheckAccess()Same
Dispatcher.Yield()Dispatcher.Yield()Same API
DispatcherPriorityDispatcherPrioritySame enum

Animations​

WPFAvaloniaNotes
StoryboardAnimationDifferent API
DoubleAnimationKeyframe animationsUse KeyFrame with Cue
BeginStoryboardAnimations declared in Style.AnimationsTriggered by pseudo-classes
EasingFunctionEasing propertySame easing types available
Transitions (UWP)TransitionsProperty change animations
CompositionTarget.RenderingTopLevel.RequestAnimationFrame()Per-frame callback on UI thread; see also CompositionCustomVisualHandler for render-thread callbacks

Window​

WPFAvaloniaNotes
AllowsTransparency="True"TransparencyLevelHint="Transparent"Avalonia does not support WPF-like transparent click-through behavior.
WindowStyle="None"WindowDecorations="None"Removes title bar and border
ResizeModeCanResizeBoolean instead of enum

Graphics​

WPFAvaloniaNotes
SolidColorBrushSolidColorBrushSame
LinearGradientBrushLinearGradientBrushSame
RadialGradientBrushRadialGradientBrushSame
ImageBrushImageBrushSame
VisualBrushVisualBrushSame
DrawingBrushNot availableUse VisualBrush
BitmapEffectEffect propertyBlurEffect, DropShadowEffect
DropShadowEffectBoxShadow on BorderDifferent API, CSS-like
RenderTransformRenderTransformSame; also supports CSS shorthand
LayoutTransformLayoutTransformControlWrap in a control
ClipClipSame
OpacityMaskOpacityMaskSame
PathPathSame; same mini-language

Platform services​

WPFAvaloniaNotes
SystemParameters.PrimaryScreenWidthTopLevel.GetTopLevel(this).Screens.Primary.Bounds.WidthAccess via Screens on any TopLevel
System.Windows.Forms.Screen.AllScreensTopLevel.GetTopLevel(this).Screens.AllReturns all connected monitors
System.Windows.Forms.Screen.PrimaryScreen.WorkingAreaTopLevel.GetTopLevel(this).Screens.Primary.WorkingAreaExcludes taskbar/dock
PresentationSource.FromVisual().CompositionTarget.TransformToDeviceTopLevel.GetTopLevel(this).Screens.Primary.ScalingDPI scaling factor

See Working with screens for full usage details.

File structure​

WPFAvalonia
.xaml extension.axaml extension
App.xamlApp.axaml
MainWindow.xamlMainWindow.axaml
.xaml.cs code-behind.axaml.cs code-behind
.csproj WPF SDK.csproj Avalonia SDK

Common gotchas​

  1. No triggers: Avalonia uses pseudo-classes and CSS-like selectors instead of WPF triggers. See Pseudo-Classes.

  2. Style selectors not TargetType: Styles use CSS-like selectors (Button.primary:pointerover) instead of TargetType + Triggers.

  3. x:Name not Name: Use x:Name in Avalonia XAML. The Name property exists but x:Name is standard.

  4. Binding path syntax: Use #elementName.Property instead of ElementName=elementName, Path=Property. Use $parent[Type] instead of RelativeSource AncestorType.

  5. No RoutedCommand: Avalonia does not have WPF's RoutedCommand infrastructure. Use ICommand implementations (CommunityToolkit.Mvvm recommended).

  6. DataGrid is a separate package: Install Avalonia.Controls.DataGrid from NuGet.

  7. TreeDataTemplate not HierarchicalDataTemplate: The name is different but the concept is identical.

  8. Layout transforms: Use LayoutTransformControl wrapper instead of the LayoutTransform property.

  9. Assets use avares://: Resource URIs use avares://AssemblyName/path instead of pack://application:,,,/.

  10. Default binding modes: Some controls have different default binding modes than WPF. Check the control documentation if a binding does not update as expected.

See also​