left-icon

Avalonia UI Succinctly®
by Alessandro Del Sole

Previous
Chapter

of
A
A
A

CHAPTER 1

Introducing Avalonia UI

Introducing Avalonia UI


This chapter introduces Avalonia UI, explaining what it is, its purposes, and the way you build applications with this framework. It also discusses target platforms and gives you useful suggestions about finding development resources.

Introducing Avalonia UI

Avalonia UI is an open-source, cross-platform development framework for .NET. With Avalonia UI you can build native applications for Windows, macOS, Linux, iOS, Android, and WebAssembly from a single, shared codebase. From a development point of view, Avalonia UI is based on the eXtensible Application Markup Language (XAML) to design the user interface, and on C# and .NET for the imperative code, and the approach is very close to building apps with Windows Presentation Foundation (WPF).

So, if you have existing skills with this technology, building applications with Avalonia UI will be a straightforward experience. In general, any existing experience with other XAML-based development platforms (such as Avalonia UI, .NET MAUI, or Universal Windows Platform (UWP)) will make it easier to work with Avalonia UI, but WPF is certainly the closest in terms of application structure and codebase.

Note: If you are unfamiliar with XAML, do not worry—you will get an introduction in Chapter 3, “Building the user interface with XAML.” Obviously, having at least some basic knowledge is helpful to speed up your productivity and learning path.

Avalonia UI also supports F# as a programming language, but this will not be covered in this book. If you are curious to understand how Avalonia UI relates to (and differs from) WPF and UWP, the development team has published a comparison page where you can see the list of features and controls that are available in the three platforms, compared to one another.

There is also a more specific page called WPF Developer Tips that explains in more detail the differences between Avalonia UI and WPF. These differences are mostly related to syntax, but in some cases, you will find important notes that will save you some time at coding time, so I recommend reading it.

Development environment and targets

Avalonia UI works with any .NET version that supports the .NET Standard 2.0 specifications. In addition, official support is offered for Avalonia on Windows 8 and later, and on macOS, High Sierra 10.13 and later. Official support is also offered for the following Linux distributions:

·     Debian 9 and later

·     Ubuntu 16.04 and later

·     Fedora 30 and later

The supported development environments are Microsoft Visual Studio 2017 and later, and JetBrains Rider 2020.3 and later. As you will learn in Chapter 2, you could set up an Avalonia UI project only by using the .NET Command Line Interface (CLI), but in practice, you will also need a visual designer and coding support that can only be offered by an integrated development environment like Visual Studio. At the moment, Visual Studio for Mac is not supported by Avalonia UI as an integrated development environment, so you will need JetBrains Rider if you plan to develop with Avalonia UI on the Mac.

Cross-platform WPF with Avalonia XPF

The Avalonia UI is currently working on a commercial product called Avalonia XPF, which allows for building WPF applications that run on Windows, macOS, and Linux from a shared codebase. Avalonia XPF specifically targets WPF applications and will ship with a migration analysis tool that will make it easier to update existing WPF projects to be compatible with the Avalonia development framework. It will make them available on the three major desktop systems.

At the moment, Avalonia XPF is only available as an on-demand preview, and it is not generally available. It will be a paid product with different licenses and enterprise-level support. If you are interested in migrating your WPF projects to a cross-platform environment, you might want to keep an eye on the Avalonia XPF website.

How Avalonia UI works

When you open the Avalonia UI website, the following phrase appears: Pixel Perfect on Every Platform. This is exactly the summary of how Avalonia UI works. It generates the user interface by drawing pixels. To do so, it relies on the popular SkiaSharp graphic library. The implication for this is the possibility of supporting any platform that can draw pixels and receive events.

Currently, Avalonia UI supports .NET, Mono, and .NET Framework, but support for other platforms is available via the Avalonia API. In addition, Avalonia UI is designed to work cross-platform, but it has no dependency on other cross-platform technologies like .NET MAUI, for example. It uses the same underlying technologies to achieve native performance, resulting in a fast environment that can also run on low-powered devices like the Raspberry Pi.

System prerequisites

To follow along with the examples in this book, you’ll need to have Microsoft Visual Studio 2022 installed on your machine. The free Community edition is sufficient. In the Visual Studio Installer, make sure you have the .NET Desktop Development workload enabled and that you have at least .NET 6—though .NET 7 is the recommended choice.

If you plan to target mobile devices, make sure the Android SDK Setup component is selected in the list of individual components. My suggestion for the best mobile development experience is selecting the .NET Multi-platform App UI development workload. Even if you will not work with .NET MAUI when using Avalonia UI, this workload will ensure that all the necessary runtime components, emulators, and SDKs for mobile app development will be installed on your machine.

Source code and examples

As an open-source project, the full source code for the Avalonia UI framework can be found on GitHub. If you want to understand how the platform has been built, you can browse, download, and compile the code on your machine.

Tip: You will need either .NET Core 3.1 SDK or .NET 6.0 SDK to build the Avalonia UI source code on your machine. In addition, the development team has published a guide with instructions on how to work with the source code effectively.

There is also a specific repository for sample applications built upon Avalonia UI called Avalonia.Samples where you can find more sophisticated code that leverages advanced programming patterns, such as Model-View-ViewModel (MVVM). It is updated quite frequently, and it is a good reference.

Chapter summary

Avalonia UI is an open-source framework that allows for creating cross-platform projects for desktop and mobile systems and web browsers. It is based on XAML and C#, and the approach is very close to building apps with WPF. Avalonia UI supports Visual Studio on Windows and JetBrains Rider as integrated development tools, but this book will only cover Visual Studio.

In the next chapter, you will learn how to configure the development environment to start building your applications.

Scroll To Top
Disclaimer

DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.