Discovering the potential of Windows Presentation Foundation
The user interface is an important aspect of software development that in most cases defines the first impression the customer gets of an application. We’ve seen lots of great software with poor, overly-simple interfaces, or on the contrary, sophisticated ones that sacrifice functionality, intuitiveness and/or efficiency. Windows Presentation Foundation (WPF) is Microsoft’s response to the need of 21th century-worthy user interfaces that are also easy to implement and use.
Why WPF?
As mentioned in Adam Nathan’s book ‘Windows Presentation Foundation Unleashed‘, there are six major benefits WPF has over the previous Microsoft technologies that shared its purpose (like GDI+, Windows Forms):
- Broad integration. WPF integrates all the necessary technologies for developing 2D, 3D, audio, video, rich documents, and so forth, avoiding the need to learn, and implement several independent technologies.
- Resolution independence. Due to the emphasis on vector graphics, WPF applications can be resolution independent, and contents of an application can automatically resize when the application itself resizes.
- Hardware acceleration. Since WPF is built on top of Direct3D, everything from 3D graphics to text gets rendered by hardware, making every application -not only games- benefit from powerful video cards. However, if no powerful hardware is present, WPF still has a software rendering pipeline so that the hardware isn’t a requirement for WPF applications to run.
- Declarative programming. The use of Extensible Application Markup Language (XAML) in WPF makes it possible to leverage the use of declarative programming to an incredible level of expressiveness, enabling graphic designers to contribute to not only the look and feel of the application, but also some behavior that is usually coded by developers.
- Rich composition and customization. WPF controls are extremely customizable, so it is possible to dramatically alter the looks of any control without affecting its functionality.
- Easy deployment. WPF provides support for deploying Windows applications through Windows Installer or ClickOnce, and even hosting them in a web browser (although the browser must be IE7 or further).
An interesting fact about WPF is that, apart from being part of the .Net Framework and designed for managed code, it is also implemented largely in managed code.
XAML
The introduction of this new markup language greatly simplifies the creation of a UI for the .NET framework, as it enables the use of declarative markup that directly represent the instantiation of managed objects, which can be later referenced through code-behind files. This is achieved by using partial class definitions; the window class is defined as a partial class when a window is created in XAML, and it’s explicitly defined as a partial class in the code-behind file.
This approach makes it possible to separate the UI runtime logic from the UI definition itself, which is an extraordinary benefit for making extensible, modular applications, especially if design patterns such as the ones facilitated by Prism are used.
Customization & Simplicity
At first sight, WPF may not seem easy to learn, since it introduces a lot of new concepts. But it has what I think is absolutely essential for any technology: it enables an extreme degree of customization, while keeping the simplicity of default values prepared for the most common scenarios. While I think both are very important, it’s not uncommon to see a technology sacrificing one to achieve the other. That’s what I think WPF accomplishes greatly, and I realize a lot of emphasis has been put in combining those two aspects. An example of this is the use of ControlTemplates: controls have a default template that defines their most usual appearance (such as a button being the typical grey rectangle we all know), but a custom template can be applied to completely redefine the way they look without altering, however, how they behave.

As for the learning curve, once you’ve grasped the main new concepts introduced in WPF (that is, the theory), everything else is really straightforward, and the initial overhead of learning those concepts is greatly compensated by the simplicity of creating applications with it.
Although XAML syntax may seem a little bit confusing at first sight, integration with Visual Studio and tools like Expression Blend makes it easy to develop applications without being an expert at all: just having an idea of what WPF is about is enough to start learning by trial and error and discover the whole new set of possibilities this technology offers!



