Avalonia 12 breaking changes
This page lists all the breaking changes between Avalonia 11 and 12 and provides migration guidance and alternatives.
.NET support updated
Avalonia version 12 dropped support for .NET Framework and .NET Standard. Only .NET 8 and later are supported.
We recommend targeting .NET 10.
If your project targets Android or iOS, only .NET 10 is supported. This is to match the support Microsoft provides for the underlying .NET SDK.
Update your Avalonia projects to a supported .NET version.
Example:
-<TargetFramework>netstandard2.0</TargetFramework>
+<TargetFramework>net10.0</TargetFramework>
PR: #19869
Avalonia version 12
The major version of Avalonia is now 12, up from 11.
Upgrade all Avalonia package references to the latest 12 patch version, either in your favorite IDE or by editing the project files.
We recommend choosing the latest release from the official GitHub Releases page.
Example:
-<PackageReference Include="Avalonia" Version="11.3.12" />
+<PackageReference Include="Avalonia" Version="12.0.0" />
-<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.12" />
+<PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.0" />
Avalonia.Diagnostics package removed
The Avalonia.Diagnostics package has been removed.
The Dev Tools included with Avalonia Accelerate should be used instead.
Remove the Avalonia.Diagnostics package from your projects and replace it with AvaloniaUI.DiagnosticsSupport.
To install the Accelerate Dev Tools, please follow our Dev Tools documentation.
Example:
Project file:
-<PackageReference Include="Avalonia.Diagnostics" Version="11.3.12" />
+<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.0" />
Application file:
-AttachDevTools();
+AttachDeveloperTools();
PR: #20332
Binding class hierarchy changes
The binding class hierarchy has changed. Bindings defined in XAML files (e.g., {Binding}) are unaffected. However, you must update binding usages in C# code.
The IBinding interface has been removed. Its replacement is the BindingBase class.
All types of bindings now inherit from BindingBase: ReflectionBinding, CompiledBinding, TemplateBinding, and IndexerBinding. Adjust your usage accordingly; don't assume that a BindingBase instance represents only a "standard" binding.
The Binding class is kept for compatibility and always corresponds to ReflectionBinding. To create bindings in code, we recommend using the CompiledBinding and ReflectionBinding classes directly.
The InstancedBinding class has also been removed. Its direct equivalent is BindingExpressionBase, which represents a binding applied to a given object and property.
Example:
public record Item(string Value);
-var reflectionBinding = new Binding("SomeProperty");
var reflectionBinding = new ReflectionBinding(nameof(Item.Value));
+var compiledBinding = CompiledBinding.Create((Item item) => item.Value);
Compiled bindings are enabled by default
<AvaloniaUseCompiledBindingsByDefault> is now true by default.
Any Binding usage in XAML code now maps to CompiledBinding.
Avalonia's official templates explicitly enabled this flag in created projects for several years, so recent codebases should not be affected. However, if your project didn't define this flag, it was false in previous versions.
We recommend using compiled bindings whenever possible, as they are more performant than reflection bindings and are checked for correctness at build time.
PR: #19712
Binding plugins removed
The binding plugins were intended as an extensibility point for adding features to bindings. In practice, they were not working with compiled bindings and were effectively unused by most people.
Worse, users often had to turn off the default data annotations validation plugin because it conflicted with popular frameworks such as CommunityToolkit.Mvvm.
Starting with Avalonia v12, plugins are no longer configurable. The data annotations plugin is now disabled by default.
PR: #20623
Configurable text shaper
The text shaper is now configurable independently of the rendering engine. For most applications, this change should be transparent, as HarfBuzz is used by default when UsePlatformDetect is called on the AppBuilder.
However, if your project explicitly configures a rendering engine, such as Skia via UseSkia, an InvalidOperationException with the message No text shaping system configured might be thrown on startup. In this case, the project needs to be updated with a call to UseHarfBuzz on the AppBuilder.
Example:
Project file:
+<PackageReference Include="Avalonia.HarfBuzz" Version="12.0.0" />
Application file:
AppBuilder.Configure<App>()
.UseSkia()
+ .UseHarfBuzz()
PR: #19852
[Windows] Direct2D1 support removed
Avalonia no longer provides a Direct2D rendering backend. This package was not maintained, and did not have feature and performance parity with our Skia backend. The Skia backend is now the recommended rendering backend for all usages.
Example:
Project file:
-<PackageReference Include="Avalonia.Direct2D1" Version="11.3.12" />
+<PackageReference Include="Avalonia.Skia" Version="12.0.0" />
Application file:
AppBuilder.Configure<App>()
- .UseDirect2D1()
+ .UseSkia()
PR: #20132
[Android] App initialization changed
In Avalonia 12, the way an Android application and its activities are initialized has changed, allowing subsequent activities to properly use the Application class defined in your project.
- Change your main activity to inherit from
AvaloniaMainActivity(non-generic) instead ofAvaloniaMainActivity<TApp>(generic). - Add a new class deriving from
AvaloniaAndroidApplication<TApp>and apply the[Android.App.Application]attribute to it.
Example:
[Activity]
public class MainActivity :
-AvaloniaMainActivity<App>
+AvaloniaMainActivity
{
}
+[Application]
+public class AndroidApp : AvaloniaAndroidApplication<App>
+{
+ protected AndroidApp(IntPtr javaReference, JniHandleOwnership transfer)
+ : base(javaReference, transfer)
+ {
+ }
+}
PR: #18756
[iOS] App initialization changed
In Avalonia 12, the way an iOS application is initialized has changed to use the "scenes" concept, which Apple will make mandatory in the near future.
While most applications should work without any code changes, AvaloniaAppDelegate.Window will now remain null after the app is initialized, as the window is now managed internally by the scene delegate.
If you need to access the UIWindow, we recommend overriding the AvaloniaView.MovedToWindow method to detect when the view gets attached to it.
PR: #20454
[Tizen] Avalonia.Tizen package removed
The Tizen platform is no longer supported out of the box because it lacked a maintainer.
Read Moving Tizen Support Out of Main Repository for details.
PR: #19722
[Browser] Avalonia.Browser.Blazor package removed
The Avalonia.Browser.Blazor package served as a temporary migration step while we upgraded from Avalonia's old browser backend, based on Blazor. We have now fully moved to a new backend based on WASM (Avalonia.Browser). This package was no longer maintained and has been removed.
Note that it is still possible to run Avalonia on top of Blazor by using the supported Avalonia.Browser package and its AvaloniaView class.
PR: #20105
[Headless] xUnit.net and NUnit supported versions updated
The underlying test frameworks supported by Avalonia's headless platform have been updated to their latest versions. The unit tests might need updates.
- xUnit.net support now targets version 3 (up from 2). Read xUnit.net's official migration guide for how to migrate your unit tests.
- NUnit support now targets version 4 (up from 3). Read NUnit's official migration guide for how to migrate your unit tests.
[Windows] BinaryFormatter removed
In previous versions, Avalonia used .NET's BinaryFormatter on Windows to implicitly serialize and deserialize arbitrary objects placed on the clipboard.
Microsoft has been recommending migrating away from the binary formatter since several .NET versions. Avalonia follows this guidance and no longer uses it.
Your project should explicitly serialize and deserialize objects using your preferred mechanism (JSON is a popular format).
PR: #20455
Improved touch/pen focus and selection behavior
- Selection events in
ItemsControland derived classes (e.g.,ListBox), as well asTreeViewItem, may behave differently. For example, items will be selected on touch/pen release. A newShouldTriggerSelectionvirtual method can be overridden to change the default selection behavior. - Container types (e.g.,
ListBoxItem) now always handle selection input, instead of letting the event bubble up to theirItemsControl. - Focus is now changed only when touch and pen devices are released.
TopLevel changes
To prepare the groundwork for advanced windowing features, notably templated drawn window decorations and virtual window scenarios, several changes happened in Avalonia v12:
- Despite its name, a
TopLevel(this includesWindow) object is not necessarily at the root of the visual hierarchy anymore. Code that casts the topVisualtoTopLevelno longer works. To access aTopLevelinstance, always callTopLevel.GetTopLevel(Visual). - Interfaces that were previously only implemented by
TopLevelclasses, such asIInputRoot,IRenderRoot,ILayoutRoot,ITextInputMethodRootandIEmbeddableLayoutRoot, are either removed or not accessible anymore. UseTopLevelinstead. - A new
IPresentationSourceinterface is introduced, which represents an arbitrary host for the visual tree (while not being a visual itself). To get a hold of such an instance, call the newGetPresentationSource(Visual)extension method.
PR: #20624
Window decoration changes
Avalonia v12 overhauls how the decorations (title bar, caption buttons, resize grips, etc.) of a window are drawn when the system chrome is not used:
- A new
WindowDrawnDecorationsclass is added. Its role is to provide all the window decorations through a single control. - Thanks to this new type, the
TitleBar,CaptionButtonsandChromeOverlayLayertypes are not necessary anymore and have been removed. - The
Window.ExtendClientAreaChromeHintsproperty consisted of several flags that were not always behaving as expected. This property has been removed, as theWindowDecorationsproperty in conjunction withExtendClientAreaToDecorationsHintshould be used instead.
Clipboard changes
Previously, we rewrote clipboard support to use a new IAsyncDataTransfer interface and related types. To avoid breaking compatibility, the old IDataObject interface was kept (and made obsolete) as a shim for the new system.
The IDataObject interface has been removed in Avalonia v12, along with all methods that accept that type. Its implementation, DataObject, no longer does anything.
The IClipboard interface has been simplified, with methods for reading specific formats implemented as extension methods (such as TryGetTextAsync and TryGetFile).
Read the official clipboard documentation to know how to use IAsyncDataTransfer.
Example:
// Setting a data object on the clipboard
-var data = new DataObject();
-data.Set(DataFormats.Text, "some text");
+var item = new DataTransferItem();
+item.Set(DataFormat.Text, "some text");
+var data = new DataTransfer();
+data.Add(item);
-await clipboard.SetDataObjectAsync(data);
+await clipboard.SetDataAsync(data);
Example:
// Reading text from the clipboard
-var text = await clipboard.GetTextAsync();
+var text = await clipboard.TryGetTextAsync();
PR: #20521
Multiple dispatchers support
While not technically a breaking change, Avalonia v12 now supports multiple dispatchers, one per thread.
Using Dispatcher.UIThread is still perfectly acceptable for applications. However, we recommend that library and control authors start using the AvaloniaObject.Dispatcher and Dispatcher.CurrentDispatcher properties to support multiple dispatchers properly.
Note that multiple UI threads are currently still unsupported.
PR: #18686
Dispatcher.InvokeAsync captures the execution context
This change should make most usages of asynchronous calls behave as the user would expect. AsyncLocal will work as expected, and impersonation and culture will flow from the caller.
PR: #19163
FuncMultiValueConverter accepts an IReadOnlyList
This change allows you to index values directly.
Most existing usages should be unaffected.
PR: #19936
Data validation enabled by default in custom controls
Before v12, Avalonia properties with enableDataValidation: true required overriding the UpdateDataValidation method for data validation errors to be reported for that property. Now it happens automatically.
We recommend removing UpdateDataValidation overrides that only call DataValidationErrors.SetError.
Example:
public class CustomControl
{
public static readonly StyledProperty<string?> CustomProperty =
AvaloniaProperty.Register<CustomControl, string?>("Custom", enableDataValidation: true));
- protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
- {
- if (property == CustomProperty)
- {
- DataValidationErrors.SetError(this, error);
- }
- }
}
If you need to revert to the old behavior for a given property, override UpdateDataValidation and do not call the base method for that property.
PR: #20067
[Windows] Window.ExtendClientAreaToDecorationsHint improved
On Windows, several issues with the ExtendClientAreaToDecorationsHint property have been fixed, and this property now works in all supported scenarios. Previously, various workarounds were suggested, such as adding or removing margins in the affected window (notably when the window is maximized). All earlier workarounds should now be removed.
PR: #20217
Text formatting constructors modified
GenericTextRunProperties, TextCollapsingProperties, and TextShaperOptions all had two constructors: one with a FontFeatureCollection parameter, and one without.
They have been merged into a single constructor with an optional parameter.
Depending on the overload used, you might need to reorder the arguments, since FontFeatureCollection is now the last parameter.
PR: #20527
Access keys are triggered by symbol
Previously, the underlying virtual key triggered access keys, so accented characters or numbers could not be used as access keys.
To align with other popular UI frameworks and user expectations, access keys are now triggered by the symbol printed on the key.
PR: #20662
Font support updated
To ensure consistent font loading across platforms, Avalonia v12 includes its own font parser.
Some legacy fonts that are not TrueType (.ttf) or OpenType (.otf) are no longer supported. Such fonts include the ancient Type 1 Font format (.pfb/.pfm).
PR: #19852
Screen is abstract
The Screen class has several internal implementations, and the base class was constructible only for legacy reasons.
In Avalonia v12, it is now abstract. Do not construct a Screen class. Instead, get an existing instance from its members (e.g., Screens.All, Screens.Primary, Screens.ScreenFromWindow, etc.).
PR: #20529
ResourcesChangedEventArgs is a struct
For performance purposes, ResourcesChangedEventArgs is now a struct.
Most projects never construct instances of this type, as it's mainly used through the StyledElement.ResourcesChanged event.
If you did construct ResourcesChangedEventArgs, call ResourceChangedEventArgs.Create instead.
PR: #20576
Gesture events moved
All the attached events previously declared in the Gestures class (such as ScrollGesture, Pinch, etc.) have been moved to InputElement, making them available to all elements by default. Remove the Gestures. prefix from your XAML files.
The Gestures class is not public anymore.
Example:
-<Button Gestures.Pinch="Button_Pinch" />
+<Button Pinch="Button_Pinch" />
PR: #20789
Removed members
Avalonia.Android.Platform.IInsetsManager.DisplayEdgeToEdge property
Reason: this property was obsolete since Avalonia 11.
Resolution: use Avalonia.Android.Platform.IInsetsManager.DisplayEdgeToEdgePreference instead.
PR: #20617
Avalonia.Animation.CustomAnimatorBase/CustomAnimatorBase<T> class
Reason: this class was obsolete since Avalonia 11.
Resolution: use Avalonia.Animation.InterpolatingAnimator<T> instead.
PR: #20613
Avalonia.Animation.Easings.CubicBezierEasing class
Reason: this class was obsolete since Avalonia 11 and did nothing.
Resolution: use Avalonia.Animation.Easings.SplineEasing instead.
PR: #20613
Avalonia.AppBuilder.LifetimeOverride property
Reason: this property was obsolete since Avalonia 11 and did nothing.
Resolution: use any predefined lifetime instead.
PR: #20617
Avalonia.AvaloniaObjectExtensions.Bind method
Reason: this method was obsolete since Avalonia 11.
Resolution: use AvaloniaObject.Bind instead.
PR: #20613
Avalonia.Controls.ApplicationLifetimes.IActivatableApplicationLifetime interface
Reason: this interface was obsolete since Avalonia 11 and did nothing.
Resolution: use Application.Current.TryGetFeature<IActivatableLifetime> instead.
PR: #20617
Avalonia.Controls.AutoCompleteBox.BindingEvaluator class
Reason: this class is an implementation detail that was wrongly exposed publicly.
Resolution: use an alternative implementation (not provided by Avalonia).
PR: #20596
Avalonia.Controls.Chrome.CaptionButtons class
Reason: see the Window decoration changes section.
Resolution: use Avalonia.Controls.Chrome.WindowDrawnDecorations instead.
PR: #20770
Avalonia.Controls.Chrome.TitleBar class
Reason: see the Window decoration changes section.
Resolution: use Avalonia.Controls.Chrome.WindowDrawnDecorations instead.
PR: #20770
Avalonia.Controls.ContextMenu.PlacementMode property
Reason: this property was obsolete since Avalonia 11.
Resolution: use Avalonia.Controls.ContextMenu.Placement instead.
PR: #20617
Avalonia.Controls.Diagnostics.IPopupHostProvider interface
Reason: this interface is an implementation detail that was exposed publicly for legacy reasons. It's now a private API.
Resolution: use Avalonia.Controls.Primitives.Popup instead.
PR: #20732
Avalonia.Controls.FileDialog class
Reason: this class was obsolete since Avalonia 11.
Resolution: use Avalonia.Platform.Storage.IStorageProvider instead.
PR: #20617
Avalonia.Controls.FileSystemDialog class
Reason: this class was obsolete since Avalonia 11.
Resolution: use Avalonia.Platform.Storage.IStorageProvider instead.
PR: #20617
Avalonia.Controls.Generators.ItemContainerGenerator.ContainerFromIndex method
Reason: this method was obsolete since Avalonia 11.
Resolution: use Avalonia.Controls.ItemsControl.ContainerFromIndex instead.
PR: #20617
Avalonia.Controls.Generators.ItemContainerGenerator.IndexFromContainer method
Reason: this method was obsolete since Avalonia 11.
Resolution: use Avalonia.Controls.ItemsControl.IndexFromContainer instead.
PR: #20617
Avalonia.Controls.Generators.TreeContainerIndex class
Reason: this class was obsolete since Avalonia 11.
Resolution: use TreeView instead.
PR: #20617
Avalonia.Controls.Generators.TreeItemContainerGenerator class
Reason: this was equivalent to ItemContainerGenerator.
Resolution: use Avalonia.Controls.Generator.ItemContainerGenerator instead.
PR: #20617
Avalonia.Controls.ItemsControl.ItemsControlFromItemContaner method
Reason: this method was obsolete since Avalonia 11.
Resolution: use Avalonia.Controls.ItemsControl.ItemsControlFromItemContainer instead.
PR: #20617
Avalonia.Controls.NativeMenuBar.EnableMenuItemClickForwarding property
Reason: this property did not do anything.
Resolution: remove the usages.
PR: #20577
Avalonia.Controls.NativeMenuItemToggleType enum
Reason: this enum was merged with MenuItemToggleType.
Resolution: use Avalonia.Controls.MenuItemToggleType instead.
PR: #20577
Avalonia.Controls.OpenFileDialog class
Reason: this class was obsolete since Avalonia 11.
Resolution: use Avalonia.Platform.Storage.IStorageProvider.OpenFilePickerAsync instead.
PR: #20617
Avalonia.Controls.OpenFolderDialog class
Reason: this class was obsolete since Avalonia 11.
Resolution: use Avalonia.Platform.Storage.IStorageProvider.OpenFolderPickerAsync instead.
PR: #20617
Avalonia.Controls.Primitives.ChromeOverlayLayer class
Reason: see the Window decoration changes section.
Resolution: use Avalonia.Controls.Chrome.WindowDrawnDecorations instead.
PR: #20732
Avalonia.Controls.Primitives.IPopupHost interface
Reason: this interface is an implementation detail that was exposed publicly for legacy reasons. It's now a private API.
Resolution: use Avalonia.Controls.Primitives.Popup instead.
PR: #20597
Avalonia.Controls.Primitives.LightDismissOverlayLayer class
Reason: this interface is an implementation detail that was exposed publicly for legacy reasons. It's now a private API.
Resolution: use a full Avalonia.Controls.Primitives.VisualLayerManager if a new stack of layers is needed.
PR: #20732
Avalonia.Controls.Primitives.OverlayPopupHost.CreatePopupHost method
Reason: this method is an implementation detail that was exposed publicly for legacy reasons. It's now a private API.
Resolution: use Avalonia.Controls.Primitives.Popup instead.
PR: #20597
Avalonia.Controls.Primitives.ToggleButton.Checked/Unchecked/Indeterminate events
Reason: these events were obsolete since Avalonia 11.
Resolution: use Avalonia.Controls.Primitives.ToggleButton.IsCheckedChanged instead.
PR: #20617
Avalonia.Controls.Primitives.VisualLayerManager.AdornerLayer property
Reason: see the Window decoration changes section.
Resolution: use Avalonia.Controls.Primitives.AdornerLayer.GetAdornerLayer instead.
PR: #20732
Avalonia.Controls.Primitives.VisualLayerManager.ChromeOverlayLayer property
Reason: see the Window decoration changes section.
Resolution: use Avalonia.Controls.Chrome.WindowDrawnDecorations instead.
PR: #20732