This article is more than 1 year old
WinUI and WinRT: Official modern Windows API now universal thanks to WebAssembly
C# and XAML devs get path to what UWP promised but never delivered
At Microsoft's recent Ignite conference, the company promoted WinUI as the best path for desktop developers, and pointed towards the third-party Uno platform as an option for Windows 7 or web deployment.
"WinUI 3.0 is the future of native UX development on Windows," said Microsoft's principal program manager, James Clarke, at the event earlier this month. Weary devs have heard this kind of line before.
That said, WinUI is not really a new thing, but rather the next phase for the Universal Windows Platform (UWP) introduced with Windows 10, which itself was based on the "Modern" platform devised for Windows 8.
The WinUI name was originally devised to describe the library of controls supported by XAML, Microsoft's XML language for describing a user interface. Now in WinUI 3.0, currently in alpha preview, it is intended to describe the entire UI stack in Windows 10.
There is a bit of fudge because the old Win32 API still exists, and Win32 applications still run, but the intention is that we think of WinUI as the native Windows UI stack. The old idea that developers have to choose between UWP or desktop applications has gone, with Win32 applications having full access to the WinRT API used by UWP or WinUI, as well as WinUI controls via a technology called XAML Islands; and WinUI 3.0 applications able to behave like desktop applications. WinUI 3.0 works on Windows 10 1703 and higher.
Evolving the Windows development platform. WinUI and the WinRT API dominate, with Win32 continuing as a legacy option
A further implication of this approach is that Microsoft does not intend to do more than minimal further work on the Win32 API. Old frameworks such as Windows Forms and WPF (Windows Presentation Foundation) will largely be left alone. The major effort has been to get them running on .NET Core, the modern and open-source version of .NET, and to allow developers to extend applications with WinUI features.
WinRT is not better in all respects
Microsoft's historical decision to create WinRT and to leave Win32 developers frozen in time has been costly. Take-up for UWP and WinRT has been limited for several reasons. One is compatibility.
There is still plenty of Windows 7 out there. The latest Statcounter figures show only 63 per cent of global Windows users on Windows 10, with 28 per cent still on Windows 7. Any developer wanting broad reach on Windows has been unable to use WinRT, though for line-of-business applications where the target platform is controlled this is not such a problem.
Another issue is that WinRT is not unequivocally better. RadialGradientBrush, for drawing radial graphics, has been in WPF for years and is only now coming to WinUI. Density of information has been another issue, with more white space a feature of the modern, touch-friendly UWP or WinUI controls. Third, Microsoft has not replicated the ease of development found in Windows Forms for quick and dirty business applications.
The pendulum is swinging, though. New features on the WinRT side are making Win32 apps look dated in some respects, and Windows 7 is gradually diminishing – it goes out of support for many users on 14 January 2020.
However, it is still a confusing picture, especially for .NET developers who bought into XAML and WPF or perhaps Silverlight, a cross-platform version of WPF which a decade ago looked like it might be the future. One of the annoyances is that WinUI XAML is different from WPF XAML, and Xamarin Forms XAML different again, with no easy porting between the three.
We chat to Uno boss
At Ignite The Register spoke to Jérôme Laban, CTO of the Uno Platform. This third-party GUI from French company nventive does what Microsoft never did with the "universal" Windows Platform: it makes it cross-platform for Windows, iOS, Android and web.
Laban, like many Windows developers, faced a problem when he saw that iOS and Android were growing as Windows Phone faded away. "We had a team of 40 developers and designers, and what do we do? People are interested in iOS and Android and we have a set of developers that are trained on XAML and C#," he said.
Laban said he liked UWP XAML with its scaling capabilities but did not like that it was Windows-only. He therefore started work on "emulating the behaviour of UWP XAML on top of iOS and Android. We build on top of Xamarin, the purest Xamarin, not Xamarin Forms."
The big deal for Laban was when Microsoft made WinUI open source. "That means we can translate them from C++ to C#, and have the exact same behaviour that WinUI has on Windows," he said.
Xamarin is itself based partly on Mono, the old open-source implementation of .NET that predates .NET Core. Two years ago the Mono team started work on Mono Wasm, a version of Mono for WebAssembly, and the Uno developers took note. "In the course of a few months an interpreter was added to Mono. It was not fast. But the behaviour was exactly the same as it is on Linux or Android. We said, we have a large C# codebase, why not put that on Mono for Web Assembly?"
The outcome is that the Uno Platform now runs in the browser – extending reach to Windows 7, Mac and Linux. This also gives a route to cross-platform desktop applications via embedded browser technologies, using Chromium-based Electron, for example. In the browser Uno for WebAssembly has only the permissions of the browser, but when embedded you can call additional native APIs.
The system works today, Laban said. "Mono for Web Assembly needs to improve, and LLVM needs to improve, scripting needs to improve, the Web Assembly standard needs to improve, so lots of things need to move for the whole thing to be more efficient. But it is in a damn good place for now. It actually works. It is not efficient enough for some specific scenarios, but for applications for the intranet, or line of business applications, it is perfect as it is right now. Anything a Silverlight application can do, you can do with Web Assembly."
At Ignite, Microsoft gave Uno a measure of official support. At WinUI sessions, Uno appeared on the slides as a route to Windows 7 support. It even solves a problem for Xamarin Forms, with a renderer that enables Xamarin Forms in the browser.
Uno is open source under the Apache 2.0 licence.
One of the frustrations with .NET Core is that there is no cross-platform GUI library. Microsoft is considering taking WinUI cross-platform and was gathering opinions on the subject at Ignite. Such a move would undoubtedly increase interest in WinUI, but would also confuse matters by adding yet more options into Microsoft's already confusing mix.
Microsoft claims that there are 900 million devices running Windows 10. It is a sizeable market, though gaming aside, largely a business market for most developers. .NET developers targeting Windows have had difficult choices to make, but now – far too late – it looks as if WinUI will be a viable solution in many scenarios. ®