GUI frameworks for .NET – Part 2: WPF and WinUI 3

This time the series of articles deals with the newer GUI frameworks Windows Presentation Foundation and Windows UI Library 3.

listen Print view
.NET badge

(Image: erzeugt mit KI durch iX)

21 min. read
By
  • Dr. Holger Schwichtenberg
Contents

After the first part of this series dealt with Windows Forms, we will now look at Windows Presentation Foundation (WPF) and Windows UI Library 3 (WinUI 3). Both GUI frameworks are based on XAML (eXtensible Application Markup Language). XAML is an XML-based markup language. It combines the structural description, content, layout, design, transformations and animations into a single language – unlike websites, where these competencies are divided between HTML and CSS, but sometimes also mixed (and in some cases JavaScript is also required to achieve the same results as in XAML).

Dr. Holger Schwichtenberg
Dr. Holger Schwichtenberg

Dr Holger Schwichtenberg is Chief Technology Expert at MAXIMAGO Software Development. Together with the team of experts at www.IT-Visions.de, he also offers consulting and training in Microsoft, Java and web technologies. He speaks at specialist conferences and is the author of numerous specialist books.

XAML is an XML-based language with which individual .NET objects and entire object trees can be expressed in XML form. Within WPF, this is used to describe interface elements such as <TextBlock>, <TextBox>, <Button>, <ListBox>, <ToolTip>, <Line>, <Polygon>, <MediaElement> and many more. Elements are parts of containers that determine the arrangement, such as <Canvas>, <Grid>, <DockPanel> and <Frame>.

Each XAML element has a .NET class of the same name. XAML interfaces can therefore also be created code-based, but this is rather rare and typically only occurs in metadata-based applications, whose graphical interfaces are only created dynamically at runtime.

The Windows Presentation Foundation (WPF, formerly codenamed Avalon) was introduced in .NET Framework 3.0 in 2006 and, like Windows Forms, has also been available in modern .NET since .NET Core 3.0. The .NET classes for the XAML controls in WPF are located in the .NET class library in the System.Windows namespace in the .NET assemblies PresentationCore.dll and PresentationFramework.dll.

Just as with Windows Forms, there is a powerful WYSIWYG designer for WPF within Visual Studio that generates XAML code. Many WPF developers prefer to enter XAML tags directly instead of using the designer because they are more productive using the keyboard than the mouse.

The localization of applications in the WPF Designer is not as easy as in Windows Forms. In addition to the Visual Studio Designer, there is a special designer tool for WPF, Blend, which was initially a stand-alone program from 2007. It was first called Expression Interactive Designer, then Microsoft Expression Blend. Since 2012, there has only been Blend integrated into Visual Studio (Microsoft Blend for Visual Studio).

Unlike Windows Forms, WPF offers a live view in the development environment and hot reloading when debugging. This means that developers can change the interface when debugging and see the changes directly in the running application without having to exit and restart the application.

WPF allows a good separation between interface description and program code. A modified version of the Model-View-Controller pattern has established itself under the name Model-View-ViewModel (MVVM). As mentioned on the subject of Windows Forms, MVVM is now also possible in Windows Forms in some places. Nevertheless, the possibilities of data binding in WPF remain clearly superior to those in Windows Forms; in WPF there is a declarative data binding for all properties of each control element, including extensible type converters. You can bind to other GUI elements or any data sources in the form of typed .NET objects.

Videos by heise

It is also much easier to adapt the design of a user interface in WPF than in Windows Forms, as all XAML controls can be combined with each other (for example, a checkbox can be part of a selection field or a video background can run in an input field), adapted using styles and also fundamentally redesigned using control templates. Styles and control templates can be defined centrally via so-called resource dictionaries and then used for several WPF controls. This allows developers to ensure, for example, that all TextBox elements of a window or the entire WPF application look the same.

In addition, responsive design, i.e. adapting a user interface to different screen sizes and resolutions, is easier to implement with WPF than with Windows Forms. WPF uses vector-based rendering. This makes it easy to create applications with magnification functions (zoom) or applications that can be used on different monitor sizes. However, WPF does not offer SVG integration. This requires a community project called SharpVectors. WPF offers integrated support for transformations and animation of any interface elements. The WPF input controls allow voice and pen input.

Since .NET 9.0, Microsoft has provided a resource dictionary with which WPF applications can adopt the Fluent Design of Windows 11 (also under Windows 10). WPF applications have a more modern look and feel than Windows Forms applications; Fluent Design further increases the visual advantage of WPF. With WPF, Microsoft has therefore significantly advanced the topics of design and user experience on Windows.

As can be seen in Figure 1, the Fluent Design interface (center and right) looks much more modern than the classic WPF design (left). However, changes to the standard sizes mean that adjustments to the interface are now necessary, as the entire text is no longer legible and the list has far too much spacing. In the version on the right, the sizes and spacing were then corrected manually.

Classic WPF design (left) versus WPF in Fluent Design (center and right)(Fig. 1).

(Image: Holger Schwichtenberg)

WPF renders hardware-accelerated based on Microsoft DirectX technology (DirectX version 9; in modern .NET, DirectX 11 is sometimes used in WPF). Nevertheless, WPF applications are often no more performant than their Windows Forms counterparts, which are based directly on the operating system APIs; in some cases, WPF is even slower.

WPF and XAML were not only created by Microsoft as a GUI framework for classic Windows business applications, but also allow multimedia and 3D applications, the display of documents (Open XML Paper Specification – XPS) and browser-based applications (XAML Browser Application – XBAP). However, WPF has not become established for documents and the browser. XBAP no longer exists in modern .NET. However, the System.Windows.Xps namespace still exists. As there are hardly any differences between WPF in the classic .NET Framework and modern .NET apart from the elimination of XBAP, migrating WPF interfaces to the latest version requires little effort.

WPF provides some controls for many cases. An overview of the supplied controls can be found in the WPF application "WPF Gallery", which is available in the Windows Store (see Figure 2). As with Windows Forms, higher-quality controls must be purchased from third-party providers (see Table 1). However, a ribbon control is included in the core of WPF, in the System.Windows.Controls.Ribbon class.

WPF Gallery App from the Windows Store (Fig. 2)

(Image: Holger Schwichtenberg)

Manufacturer Product
Telerik UI for WPF
DevExpress WPF Component Subscription
Infragistics Ultimate UI for WPF
Syncfusion WPF controls
Mescius (vormals GrapeCity) ComponentOne WPF UI Controls
Actipro Software WPF Controls
Xceed Toolkit plus for WPF
Text Control TX Text Control .NET
Lepo/Community WPF UI

Table 1: Selected GUI component providers for WPF

Due to the power of WPF, the learning effort for WPF is greater for beginners than for Windows Forms.

WPF has received few innovations in the last modern .NET versions, significantly fewer than Windows Forms. The improvements have mostly been in the areas of performance and accessibility. Since .NET 6.0, WPF applications (like Windows Forms) also run on Windows ARM64 systems. It was only in .NET 8.0 that Microsoft solved a major problem with WPF that had made it difficult to use WPF applications for remote desktops all these years: until now, software rendering (CPU) was the standard for connections with the Remote Desktop Protocol (RDP). GPU-based hardware rendering can only be switched on via a configuration entry as of .NET 8.0. In .NET 8.0, Microsoft has also added the OpenFolderDialog class. A third major innovation for WPF was in .NET 9.0, which was released on November 12, 2024 with the Fluent Design (already mentioned above), including support for Dark Mode of Windows 10 and 11.

WPF and the predecessor technologies can also be integrated: WPF has built-in interoperability with Win32 and Windows Forms user interfaces, meaning WPF applications can contain Windows Forms or Win32 controls. Conversely, a WPF control can be integrated into Win32 or Windows Forms windows. The installation options are the same as for Windows Forms.

Just like Windows Forms, WPF is also repeatedly pronounced dead in the media, for example in dotnetpro magazine, issue 5/2023:

  • "Now, in 2023, we have to accept: WPF is apparently on the sidetrack."
  • "The nail in the coffin was then hammered in by a Microsoft live stream in February: The development and support of WPF was outsourced by Microsoft to Microsoft's India Developer Center, which is to take on the topic with the help of two to three developers."
  • "But let's be honest: WPF is dead! It will certainly live on in its current state for more than ten years, but it won't change much."

However, I think that "dead" is not the right term here. Everything that is still delivered with current .NET versions or receives bug fixes is alive. Theming innovations in WPF in .NET 9.0 in particular have shown that there is still life in WPF.

WPF is established and proven. Therefore, WPF is used in many .NET applications and there are always new applications with WPF. However, hardly any development teams are switching from Windows Forms to WPF. Firstly, developers can achieve many things in Windows Forms with third-party component libraries and secondly, the future prospects of WPF are similar to those of Windows Forms, i.e. there are only minor improvements, but no more major innovations.

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.