A cross-platform GUI under 2 minutes with .NET via AvaloniaUI
In this post let's build a Hello World application using AvaloniaUI which is a C# library for building cross-platform desktop apps with XAML dialect.
Requirements
.NET Core SDK Link
Visual Studio 2019
Getting Started
Windows:
Create "Avalonia MVVM Application" in Visual Studio:
Open
Views/MainWindow.cs.xaml
. This is XAML code and is developed by Microsoft and is heavily used in UWP apps (Windows 10 apps). XAML is used to create graphical UI in .NET Core.Run the project. If everything is correctly setup, you will see a Window with Hello World text on it. Congratulations! It worked on first try.
Linux/Mac:
Let's see this in action on another platform. You can run this project in Linux/Mac platform after setting up .NET Core and Avalonia and running the command:
cd <project_dir>
$ dotnet run
You should now see the same window on a different platform! Let's change the Button text. Open ViewModels\MainWindowViewModel.cs
and update text of Greeting
variable. Run the project and you should see the text has changed!
Conclusion:
This is easy way to get started with cross-platform GUI apps via AvaloniaUI using .NET Core. If you wish to explore more, head over to Avalonia Docs
Leave a comment or @ me on Twitter if you need help. I plan on writing more articles covering this if there's interest.
Happy New Year 2021 in advance folks :)
Credits
Pic credits: Avalonia Docs