Jason Sultana

Hi, I'm Jason! I'm the author of this blog and am a certified Microsoft Developer / AWS Architect that's addicted to good steak, good coffee and good code!

Cross platform desktop GUIs with Avalonia

23 Jan 2021 » osx, windows, linux, dotnet, desktop

G’day guys!

It seems like programming for the desktop is almost never discussed these days, with all sorts of exciting things happening in cloud, web and mobile. While it’s true that a lot of traditional desktop programs have been revamped into web and mobile versions, there are still circumstances where a desktop application makes sense. But I think that there is one significant aspect of desktop development that may have been considered a feature in the past, is now a necessity: being cross-platform.

According to statcounter, over the past 10 years or so, Windows usage has dropped by about 20%, Mac OS usage has increased by about 20%, and Linux and Chrome OS have seen marginal increases in adoption as well. This means that if you’re developing for the desktop, you can’t simply focus on Windows and ignore the alternatives (especially Mac OS) - at least not any more.

This is probably old news to Java developers, who have been preaching write once, run everywhere since the 90s. For us .NET developers though, Windows has been our bread and butter for so long, developing a GUI for the desktop immediately brings to mind vivid images of WinForms and WPF. Sadly though, although .net core has opened up our beloved C# and dotnet platform to the open source and cross platform communities, the desktop GUI tools like WinForms and WPF did not come with them, and they remain Windows-only targets (as of January 2021). Thankfully though, there are still a few options on the table - or this would have been a rather short and depressing blog post!

There are a few options available for cross-platform desktop development using dotnet, but I decided to try out Avalonia. It integrates well with Rider, feels quite familiar for anyone with WPF and Xamarin experience, and let’s face it, it sounds cool! Anyway, I’ve only used Avalonia for less than a day, but here are my thoughts.

It’s fast!

The first thing that I noticed (with delight) is that building in Avalonia is actually quite fast - especially compared to Xamarin, which felt sluggish at times.

It’s familiar

If you’ve worked with WPF and Xamarin before, you’ll notice a lot of similarities. All platforms use XAML, MVVM bindings and a few other common concepts, so I found it fairly quick to get up and running with.

It’s consistent

Here are some screenshots from the same app compiled under OSX, Windows and Linux (Ubuntu).

Publishing an executable for Windows was incredibly easy, just as it is in Visual Studio for WPF or WinForms. For Mac, it’s a bit more involved, which is documented at https://avaloniaui.net/docs/packing/macOS. Under Linux, the process itself seemd to be straight-forward, but I did have issues running the binary once built. I suspect though that this may have been down to permissions issues on Ubuntu rather than in the build process, and I didn’t want to spend more time debugging it.

For my purposes though, Avalonia is looking quite nice, and I’m looking forward to playing with it a bit more over the next few days!

Anyway, that’s all from me for now. Catch ya!