This article is more than 1 year old

Cross-platform Windows Presentation Framework, anyone? The short answer: yes. Unpacking Avalonia

Developers liked WPF but Microsoft neglected it. Avalonia is a possible solution

Interview Avalonia, a cross-platform framework for desktop applications, has built up a considerable user community but is it a viable alternative to Microsoft's official solutions?

The name Avalonia will be familiar to long-term .NET developers. Avalon was the code name for Windows Presentation Foundation (WPF), one of the “three pillars of Longhorn”, first presented at Microsoft’s Professional Developers Conference in 2004.

The role of Avalon changed when it became apparent that Longhorn had fatal performance problems, fixed by rewriting parts of the operating system that were intended to use .NET in native code, despite long delays in what was eventually released as Windows Vista. The idea of Avalon as the native user interface for Windows died, and WPF became just another way to write .NET desktop applications.

Windows, iOS/macos, Android and Linux logos

'Developers have lost hope Microsoft will do the right thing'... Redmond urged to make WinUI cross-platform

READ MORE

Despite its uncertain start, WPF was well-liked by many of the developers and designers who got to grips with it. It is based on vector graphics so scales well on different displays, and takes advantage of the GPU and hardware acceleration. WPF draws its own controls and does not use built-in Win32 GUI components. The user interface is typically defined in XAML, an XML language. WPF even went cross-platform, in a sense, when Microsoft introduced Silverlight, cut-down WPF for embedding in web pages, and then later for Windows Phone.

Microsoft turned its back on WPF and Silverlight with the Windows 8 wave of releases back in 2012, the rumour being that the Windows team still had bad memories of Vista. Its replacement was the chunky “Metro” framework, which later morphed into the Universal Windows Platform (UWP) and is currently morphing again into WinUI and “Project Reunion”.

One piece not being reunited thought is WPF. WPF applications still run in Windows 10, and Microsoft has made it open source and done the work to make it run, for Windows only, on .NET Core, but it is not the focus of the company’s strategy and has been neglected for years.

The Mists of Avalonia

Enter Avalonia, a cross-platform, open source GUI framework which is based on WPF though it is not 100 per cent compatible.

It began back in 2013, creator Steven Kirk told The Register. “I decided to try and re-implement WPF as an open source project. Just for something to do… I did that for a few months and I wasn't really enjoying it. So I thought, I’ll just do things the way I want to, based on WPF ideas but changing things using more modern language and more modern features, and just improve things, so I thought (laughs).”

Avalonia was always intended to be cross-platform, initially using Mono and then later .NET Core after it turned up in late 2014.

Kirk also tried to improve “the verbosity and the datedness of some of [WPF's] architecture.”

The project ticked over, depending on Kirk’s time and inclination, but “when .NET Core came out, a lot of people were asking for a UI framework. There was UWP by this point, but UWP was and still is very limited in what you can do with it. And UWP doesn’t work on .NET Core either.”

Momentum behind Avalonia gathered, to the point where, around a year ago, Kirk set up a company, AvaloniaUI, with two other developers, Nikita Tsukanov and Dan Walmsley, to offer commercial support and raise funds for futher development. A busy Gitter discussion group as well as a GitHub repository with over 10,000 stars shows substantial interest, despite the lack of official Microsoft support. Kirk takes the view that the .NET world needs more projects that are independent of Microsoft in order to thrive.

Avalonia is a XAML-based framework which targets Windows via .NET Framework and .NET Core, Linux and macOS. Mobile is planned. “Work is under way. One of our commercial customers has requested it. I couldn’t give you a date,” said Kirk, who added that both iOS and Android are likely to be supported. Avalonia uses the Skia graphics library for rendering.

Why the interest in Avalonia? “I only really know about the people who have come [to] us asking for commercial support,” said Kirk. “Some customers need lower-level access than WPF gives them even though they’re just Windows.

"One is writing a 3D modeling application and because we’re open source and because we allow you to delve into the lower levels they can embed their own 3D models. Other customers have, say, a WPF application for Windows and an Objective C application for Mac and they want to consolidate them. Others are just tired of the stagnation of WPF, and have tried UWP and found it too limiting. A lot of people are attracted to us because we’re a true open source project, not backed by any big company.” Unlike in the early days, compatibility is now a high priority. “If we have to do something differently we’ll do it but that should be only out of necessity,” said Kirk.

I’m still waiting to see if the .NET Foundation can make any meaningful affect on .NET

Avalonia is a .NET Foundation project, meaning the foundation set up by Microsoft to support .NET. “We applied for it about a year ago and got accepted,” said Kirk. “It hasn’t really made any difference so far. We mainly did it because we figured that by being part of the .NET Foundation maybe gives us some sort of visibility to Microsoft to not stamp on us and replace us with their own solution ... I’m still waiting to see if the .NET Foundation can make any meaningful affect on .NET.”

One company with an important contribution is JetBrains, which supports Avalonia with its Rider IDE. “It’s made a big difference,” said Kirk. There is a Visual Studio plugin, but “first of all Visual Studio is Windows only, second writing extensions for Visual Studio is horrible, horrible, horrible,” he added. “Microsoft tend to keep breaking XAML support for us. Because it’s not something they consider. We had to move to our own .axaml extension,” he said.

[W]e figured that by being part of the .NET Foundation maybe gives us some sort of visibility to Microsoft to not stamp on us and replace us with their own solution

The chances of Microsoft coming up with its own Avalonia look slim. The closest thing is MAUI - .NET Multi-platform App UI – which is based on Xamarin Forms. There are a couple of reasons why MAUI is different though. First, although it uses XAML, it is a very different dialect from WPF. “It’s a completely different XAML language really, practically zero portability,” said Kirk.

Second, MAUI uses native controls, whereas Avalonia draws its own, which means MAUI bears the same relationship to Avalonia as SWT (Standard Widget Toolkit) does to Swing in the Java world. Native controls is “a valid approach. I wouldn’t like to say which one’s best,” he said.

Microsoft’s WPF implementation would be hard to convert to a cross-platform framework, according to Kirk. “It is so tied to the Win32 APIs. The code is not layered at all. So these Win32 calls are from the lowest level to the highest level. There is no reasonable way to abstract them.”

Avalonia is at version 0.10.

When might we see a 1.0 release?

“We’re going to completely skip 1.0. I think our next release is going to be 11.0,” said Kirk with a laugh. “There’s never going to be a moment when we say, right, we’re ready, 1.0’s there, because it’s too disparate a community, there’s always someone saying, I need to get this in. We’re stable anyway, people are using us, it’s just that the version number is not 1.0,” he added.

Avalonia is a small project and funding is a struggle at times. “The company is growing,” said Kirk, the main challenge being that selling support and custom development “can take resources away from working on the core OSS product,” he said.

There are gaps in Avalonia as well as plenty of things to fix: there are over 1,000 open issues on GitHub. One lack is a DataGrid. “One of the custom controls that people always want is a DataGrid, a combined tree and DataGrid, so we’ve been working on that. We’re considering selling that. We haven’t decided anything yet. We need to try and raise revenue to get more people working on Avalonia,” Kirk said.

With so many choices facing .NET developers building desktop applications, is Avalonia just adding to the confusion? “It is confusing, but it's less confusing than the JavaScript space,” said Kirk. “Perhaps a confusing amount of choices is a healthy thing. It’s not 100 per cent healthy but a monoculture isn’t 100 per cent healthy either. We’ll just keep going ahead doing what we’re doing.” ®

More about

TIP US OFF

Send us news


Other stories you might like