What would a cross-platform .NET UI Framework look like? Exploring Avalonia
Many years ago before WPF was the "Windows Presentation Foundation" and introduced XAML as a UI markup language for .NET, Windows, and more, there was a project codenamed "Avalon." Avalon was WPF's codename. XAML is everywhere now, and the XAML Standard is a vocabulary specification.
Avalonia is an open source project that clearly takes its inspiration from Avalon and has an unapologetic love for XAML. Steven Kirk (GitHubber by day) and a team of nearly 50 contributors are asking what would a cross-platform .NET UI Framework look like. WPF without the W, if you will.
Avalonia (formerly known as Perspex) is a multi-platform .NET UI framework. It can run on Windows, Linux, Mac OS X, iOS and Android.
YOU can try out the latest build of Avalonia available for download here:https://ci.appveyor.com/project/AvaloniaUI/Avalonia/branch/master/artifacts and probably get the "ControlCatalog.Desktop" zip file at the bottom. It includes a complete running sample app that will let you explore the available controls.
It's important note that while Avalonia may smell like WPF, it's not WPF. It's not cross-platform WPF - it's Avalonia. Make sense? Avalonia does styles differently than WPF, and actually has a lot of subtle but significant syntax improvements.
Avalonia is a multi-platform windowing toolkit - somewhat like WPF - that is intended to be multi- platform. It supports XAML, lookless controls and a flexible styling system, and runs on Windows using Direct2D and other operating systems using Gtk & Cairo.
It's in an alpha state but there's an active community excited about it and there's even a Visual Studio Extension (VSIX) to help you get File | New Project support and create an app fast. You can check out the source for the sample apps here https://github.com/AvaloniaUI/Avalonia/tree/master/samples.
Just in the last few weeks you can see commits as they explore what a Linux-based .NET Core UI app would look like.
You can get an idea of what can be done with a framework like this by taking a look at how someone forked the MSBuildStructuredLog utility and ported it to Avalonia - making it cross-platform - in just hours. You can see a video of the port in action on Twitter. There is also a cross-platform REST client you can use to call your HTTP Web APIs at https://github.com/x2bool/restofus written with Avalonia.
The project is active but also short on documentation. I'm SURE that they'd love to hear from you on Twitter or in the issues on GitHub. Perhaps you could start contributing to open source and help Avalonia out!
What do you think?
Sponsor: Get the latest JetBrains Rider preview for .NET Core 2.0 support, Value Tracking and Call Tracking, MSTest runner, new code inspections and refactorings, and the Parallel Stacks view in debugger.
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
Ultimately using OSS is a huge risk to a company making a product unless that OSS is massive, like jQuery for example. If you have a product that's going to last years then you need tech that will do the same.
Separation of concerns will make it easier to replace your UI but it doesn't make it zero effort. If you have a large product then if the UI OSS goes under or drops out of favour for the next big thing of the week then you are kind of screwed. It's costly to replace your UI whilst having to simultaneously implement more work. MS should take on the mantle of something like this and improve Xamarin.
XAML standard will hopefully mean that most of the UI code can be shared and you can choose to use whichever 'runtime' you want like WPF, Avalonia etc. Think I've understood it anyway!
I do like that XAML is being used as the basis for some other UI frameworks though that is awesome.
Q: Why don't you follow the WPF/UWP/Silverlight API? I have stuff I'd like to port but you're making it difficult!
A: When I started writing Avalonia, it was intended to be an OSS port of WPF (you can see how far I got here https://github.com/grokys/Avalonia) but after a while I just wasn't enjoying it - I wanted to improve things. Since this was all being done on my free time, it came down to a choice between giving up or working on something I enjoyed: I chose the latter.
At this point I never really expected that anyone would actually want to use this thing I was writing so I didn't give much thought to keeping compatibility. Since people have started noticing Avalonia and even using it to create applications, that has changed somewhat. Now we're trying to follow existing XAML frameworks where it makes sense, and modernise or
Q: Why don't you use native controls? Templated controls suck! They'll never look right on all platforms.
A: A very valid concern! If you want native controls take a look at https://github.com/picoe/Eto. @cwensley is doing amazing work there, and we're even using his Portable.Xaml as our XAML engine.
Yeb, UI frameworks like these are for us sane people lool
That being said, this seems like the logical place for Microsoft to take Xamarin Forms (and make it an official upgrade path for WPF).
Though no one at Microsoft is willing to discuss this or even admit the need for an upgrade path for .NET Framework applications. All we hear from Microsoft is the absurd claim that .NET Framework and .NET Core will both continue to be developed concurrently ad infinitum , which is obviously nonsense.
One reason I didn't get anywhere is that I'm an experienced .NET developer who is running away from Windows as fast as I can. I have no chops at all on linux, so I'm still very lost. In short, I need help. If I could get some for Avalonia, I could potentially give a lot back to the project. My home machines are all linux now, and that's the way it's going to stay. It's develop on linux with netcore, or not at all.
I think the project is mainly unaware of the demand for a working solution to this problem. Most of the devs I know are toying with netcore on linux, and when a real solution becomes available, I believe we will see an explosion of .net apps on linux. But, we are only close. It's not there yet, and without a common place to share and discuss issues, anyone like me will be forced to remain on the sidelines.
Please, Avalonia, set up a forum. Heck, I'd donate a year of hosting if you do :). I believe the reward would be cementing Avalonia's place as the go to interface toolkit for netcore, destined to become as popular or more popular than WinForms or WPF.
The problem with Linux is that it doesn't have any real IDE for .NET anymore. MonoDevelop doesn't have proper .NET Core support and their distribution model with flatpak is completely broken. And that was the only IDE where we could potentially get our current XAML previewer working.
I'm planning to create a plugin for Rider, but it will require quite a bit of work.
Another issue is .NET Core SDK being unable to properly build projects targeting full .NET, anything that has net461 in TargetFramework(s) is broken. Same for goes for OSX, but VS4Mac at least has .NET Core debugging support.
But community forum is a good idea, we might figure out something about that. For now you can use StackOverflow with avaloniaui tag
Avalonia still has a way of defining styles, bindings and control templates from C# code. For example, that's how our default control theme had looked two years ago:
and that's how UI was defined:
WebAssembly is doable, but we need to wait for support from Mono or corert.
Thanks for the update. Avalonia sounds a compelling UI framework.
Comments are closed.