WPF in 2021: alive, dead or on life support?
Tags: dotnet, desktop, wpf, winforms
Published: 2021-07-26 09:39:14

Recently I've been participating in a team discussion about whether or not to choose WPF as a framework for a new "greenfield" Windows-only application. The application itself isn't expected to have a sophisticated UI, but it might be required to use WebView2 and/or some 3rd party controls for document rendering, viewing and printing.

I'm writing this post as someone with substantial .NET/WPF background, who has lots of fond memories about WPF (and some bitter ones, too). I am not trying to diminish the value of this framework, but rather to evaluate where it stands nowadays in Microsoft Desktop development roadmap. 

From what I could tell, these days even Windows Forms is getting more love from Microsoft than WPF. I hope I'm wrong, but I'm observing certain signs of WPF being currently either shelved or placed into a very low-maintenance support mode:

 - [The WPF roadmap itself](https://github.com/dotnet/wpf/blob/main/roadmap.md) (or, pretty much, the lack of it, if compared to [that of WinForms](https://github.com/dotnet/winforms/blob/main/docs/roadmap.md)). According to this document, the only ongoing effort is *"incorporating .NET Framework servicing fixes into .NET Core 3.1 and .NET 5"*.
<br>

 - ["Is this repo dead"](https://github.com/dotnet/wpf/issues/3904) issue in the WPF repo. Lots of interesting comments in that thread, particularly, [this one](https://github.com/dotnet/wpf/issues/3904#issuecomment-744274636):
<br>

    > *The real reason was already communicated on community calls over on YouTube. The team was merged with WinUI and created from zero, apparently everyone from the original team is gone, and the new team is very resource constrained so they don't manage to deliver more than a couple of fixes. Now we can complain that instead of doing WPF, WinUI, MAUI, Blazor on Electron (what a bad idea!) they should focus on just having one UI-vnext framework, but after UWP failure, they don't seem to be able to decide what to do, each group talks differently about the "vision".*

    Some folks in that thread even voiced initiatives to fork WPF and maintain it independently of Microsoft.
<br> 

 - Microsoft's Igor Velikorossov on what's new in Windows Forms: 
  - For .NET 5: https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0. 
  - For .NET 6 Preview 5: 
  https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-in-net-6-0-preview-5
    
    <br>It's great to see WinForms being actively maintained, but what about WPF? Check out the grieving readers' [comments](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/#comment-8171). Back then, Microsoft's PM Premalini David [replied](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/#comment-8274) with a promise of boosting up the WPF team internal resources. Looking at [the WPF repo commit history](https://github.com/dotnet/wpf/commits/main) now, that doesn't seem to have been happening yet.
<br>

 - ["What's new in WPF for .NET 5"](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/getting-started/whats-new?view=netframeworkdesktop-4.8&viewFallbackFrom=netdesktop-5.0) on docs.microsoft.com. Actually, this page doesn't exist for .NET 5, it falls back to the .NET Framework 4.x content, when you choose ".NET 5". Besides some information on [adding ARM CPU support](https://github.com/dotnet/wpf/issues/4117), I couldn't find any details about what's new in WPF since it got ported to .NET Core 3 in 2019. 

    <br>On a side note, the "what's new" section [does exist](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/whats-new/?view=netdesktop-5.0) for .NET 5 Windows Forms.

I expected WPF to be an ultimate container for hosting WebView2, to help modernizing the enterprise desktop WPF apps, which typically still use the legacy IE11-based [`WebBrowser`](https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.webbrowser?view=net-5.0) control. As of now, this is far from being the case, either:

 - Rick Strahl's blog post about his titanic efforts on integrating WebView2 into his WPF-based Markdown Monster Editor: <br>https://weblog.west-wind.com/posts/2021/Apr/15/WebView2-Forwarding-Alt-Keys-to-a-Host-WPF-Window.
<br>

 - My own struggle with WPF + WebView2 keyboard and focus issues:<br>https://github.com/MicrosoftEdge/WebView2Feedback/issues/468#issuecomment-855810839. I believe that can't be properly resolved without making [changes on the WPF side](https://github.com/dotnet/wpf/issues/4637).

Overall, while there are some ongoing efforts from other teams at Microsoft to continue supporting WPF as a platform (that includes WebView2, BlazorWebView, XAML Islands, Visual Studio Designers), [the WPF GitHub repo itself](https://github.com/dotnet/wpf/commits/main) has been very quiet lately.

<hr>

What's on Microsoft's own radar for Windows-only UI development these days? Well, the official future path appears to be [WinUI 3](https://docs.microsoft.com/en-us/windows/apps/winui/). It was in the spotlight during Build 2021 and the recent Windows 11 presentation event. The modern [Windows Terminal](https://github.com/microsoft/terminal) app — a big open-source hit enjoying a well-deserved recognition — [is built with WinUI](https://devblogs.microsoft.com/commandline/building-windows-terminal-with-winui) and mostly in C++.

Microsoft also seems to be big about [WebView2](https://docs.microsoft.com/en-us/microsoft-edge/webview2/) for the apps where HTML UI is shared between Web and Desktop. The upcoming Teams 2.0 is a good example of such approach, it's a thin WinUI host for WebView2. I ranted with more details about [the new Teams 2.0 architecture](https://dev.to/noseratio/some-thoughts-on-the-new-microsoft-teams-2-0-architecture-webview2-reactjs-1gf1) (TLTR: it doesn't use .NET on the client side at all). 

Apparently, Microsoft is also well invested into [React Native for Windows](https://github.com/microsoft/react-native-windows) (a very active repo) and [Fluent UI framework](https://www.microsoft.com/design/fluent/#/windows) (used by Office 365).

For .NET folks who want to stick with C# for sharing HTML UI between Web and Desktop (with little or no JavaScript/React/etc), [Microsoft will be releasing WebView2-based `BlazorWebView`](https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-3/#blazorwebview-controls-for-wpf-windows-forms), supported on WinForms, WPF and .NET MAUI:

> Using Blazor and a hybrid approach you can start decoupling your UI investments from WPF & Windows Forms. This is a great way to modernize existing desktop apps in a way that can be brought forward onto .NET MAUI or used on the web. You can use Blazor to modernize your existing Windows Forms and WPF apps while leveraging your existing .NET investments.

This sounds like a .NET version of Electron on steroids to me. At this stage, it isn't something I'd like to take for a ride with a new Desktop project, unless there is already a working Blazor SPA web app to wrap as a desktop app. I've tried `BlazorWebView` with a simple WinForms-based app, and currently (as of NET 6 Preview 7) [it doesn't feel close](https://github.com/dotnet/maui/issues/2341) to the production quality yet. Nevertheless, `BlazorWebView` is an impressive piece of technology, I hope it will mature and won't be abandoned.

Besides, the UI technologies Microsoft use for their own mainstream projects aren't necessarily always what they recommend to the rest of the dev world. This can be a particularly confusing domain at the moment, just check this Twitter thread by Jerry Nixon, a Microsoft engineer:

{% twitter 1407013885127933952 %}

I'd also highly recommend reading Nick Randolph's ["The Future of Windows (and Other Platforms) Development"](https://www.infoq.com/articles/future-windows-other-platforms-development). It's a great take at clarifying the confusion in the fragmented space of various Windows UI frameworks.

<hr>

To wrap it up, there is a whole array of frameworks and meta-frameworks to choose from for Windows desktop development nowadays, including some cross-platform options (visit [crossplatform.dev](https://crossplatform.dev/docs/types/) for a concise overview). A .NET developer can choose from:
 - [WinForms](https://github.com/dotnet/winforms) 
 - [WPF](https://github.com/dotnet/wpf)
 - [UWP](https://docs.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-uwp?view=vs-2019) (but be sure to read [this announcement](https://github.com/microsoft/WindowsAppSDK/discussions/1615#:~:text=what%20if%20i%20have%20a%20uwp%20app%20and%20need%20.net%205%2F6%3F))
 - [WinUI](https://github.com/microsoft/microsoft-ui-xaml)
 - [Xamarin/MAUI](https://github.com/dotnet/maui)
 - [BlazorWebView](https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-3/#blazorwebview-controls-for-wpf-windows-forms)
 - [Windows Community Toolkit](https://github.com/CommunityToolkit/WindowsCommunityToolkit) (with [MVVM Toolkit](https://docs.microsoft.com/en-us/windows/communitytoolkit/mvvm/introduction))
 - [Uno Platform](https://github.com/unoplatform)
 - [Avalonia](https://github.com/AvaloniaUI/Avalonia)
 - [Comet](https://github.com/dotnet/Comet)
 - [ReactiveUI](https://github.com/reactiveui/ReactiveUI)
 - [Chromely](https://github.com/chromelyapps/Chromely)
 - [EdgeSharp](https://github.com/webview2/EdgeSharp)
 - [Electron.NET](https://github.com/ElectronNET/Electron.NET)

 ... and more. Back to our specific app case, I personally voted for Windows Forms, as odd as it may sound in 2021.

Some pro-WinForms points:

 - it is old and battle-tested but still [being actively maintained](https://github.com/dotnet/winforms/commits/main) (unlike WPF, presently);
<br>

 - has a simple, unopinionated and well-know API;
<br>

 - uses native Win32 UI controls under the hood and therefore …
<br>

 - … is easy to integrate with other native and managed controls or modernize with [`WebView2`](https://docs.microsoft.com/en-us/microsoft-edge/webview2), [`BlazorWebView`](https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-3/#blazorwebview-controls-for-wpf-windows-forms) and/or [XAML Islands](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/xaml-islands). I'd expect fewer issues with the focus/keyboard interop as well, or at least, they should be easier to address, than with WPF.
<br>

 - can be abstracted behind something simple, like [Model-View-Presenter Pattern](https://markheath.net/post/model-view-presenter-winforms), or something advanced, like [Reactive UI](https://www.reactiveui.net/docs/guidelines/platform/windows-forms);
<br>

 - can be deployed as a single EXE <del>(~75MB)</del> without needing admin rights, Windows Store, packaging, sideloading, tweaks to the Windows Developer settings, etc (*updated*: [trimming no longer work in .NET 6 for WinForms/WPF](https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/incompatibilities)):
<br>

        dotnet new winforms -n app

        dotnet publish app -r win-x64 -c Release --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=True -p:IncludeNativeLibrariesForSelfExtract=true -p:TrimMode=Link

        dir /s app.exe

I've been using the .NET Core reincarnation of WinForms for [#DevComrade](https://github.com/postprintum/devcomrade), a small side project. It enables systemwide pasting without formatting by default, amongst a few other productivity improvement features. Building it with WinForms has been a very positive experience so far.

<hr>

## Some late updates:

- [Microsoft's announcement](https://github.com/microsoft/WindowsAppSDK/discussions/1615#:~:text=what%20if%20i%20have%20a%20uwp%20app%20and%20need%20.net%205%2F6%3F) about .NET 5/6 support **not** coming to UWP .NET projects. 
- [My take](https://www.linkedin.com/feed/update/urn:li:activity:6856737082342297600/) on the above UWP announcement.
- [**No** trimming support](https://twitter.com/noseratio/status/1455046924294189056?s=20) for WinForms and WPF projects in .NET 6.
- An [interesting thread on HN](https://news.ycombinator.com/item?id=28218174), discussing current the state of UI development with .NET, amongst other things. 
- ["The roadmap is outdated"](https://github.com/dotnet/wpf/issues/5314) issue in WPF repo. 
- I learnt that WPF is still used in [Microsoft's Powertoy project](https://github.com/microsoft/PowerToys) and in [the new Visual Studio Installer](https://twitter.com/davidwengier/status/1454915177334251521?s=20) (migrated from Electron), not to mention VS2022 itself (still a .NET Framework 4.x project though).
- There's hope that WPF team will eventually get a much needed resource boost (although still no signs this is happening, as of Nov'21): 

{% twitter 1454510032985346056 %}

Thanks for reading! Feel free to leave a comment below or [on Twitter](https://twitter.com/noseratio).