C# – First steps with C# and .NET – part 037.

By | 27/08/2021

In this tutorial, I will show you how to install and work with Avalonia and Avalonia.Templates.
First, about Avalonia:
Avalonia is a WPF/UWP-inspired cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of Operating Systems such as Windows (.NET Framework, .NET Core), Linux (via Xorg), MacOS and with experimental support for Android and iOS.
The easiest way to get started with Avalonia from Visual Studio is to install the extension from the Visual Studio Marketplace.
Create an Empty project, I rename this with this name: Avalonia001.

From the main menu I select the ToolsNuGet Package ManagerManage NuGet Packages for Solution… or use Package Manager Console and use this command, see:

This will install the Avalonia package.
Next, install Avalonia templates:

MVVM is the recommended pattern for creating Avalonia applications. The MVVM application template uses ReactiveUI to ease building applications with complex interactions.

To create a new MVVM application called MyApp in its own subdirectory, run:

To create a new Window called MyNewWindow, in the namespace MyApp run:

To create a new UserControl called MyNewView, in the namespace MyApp run:

To create a new Styles list called MyStyles, run:

To create a new ResourceDictionary called MyResources, run:

To create a new barebones application called MyApp in its own subdirectory, run:

Because I want to use an application I use this command:

The Visual Studio will refresh the source code with the new files.
If I run this the result will be a window with a text message: Welcome to Avalonia!
This message comes from MainWindow.axaml file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.