Windows Presentation Foundation (WPF) - What is it?

by Dominic Zukiewicz 29. August 2008 12:14

WPF is revolutionary as it re-invents the Windows design and programming for the Microsoft platform. But why bother?

I could write an article for hours and hours on the changes brought about with WPF. Here, I will give a very brief overview of the more visual changes brought about.

History

If you have had any experience programming Windows in .NET, VB6 or C++ MFC, you'll have heard of GDI. GDI (more recently GDI+) is an API which you use to render text images and other custom drawing functions (like lines, circles, rectangles etc). The GDI library has been around since Windows 95 and was a huge hit with developers for drawing basic elements on the page. The standard Windows forms and controls are rendered by the User.dll (more recently User32.dll).

The problem that faces GDI in the modern computer is that it is implemented in software. In 1995, this is a sensible solution, but in 2008 the average computer has a half decent graphics processor. Also, DirectX has matured a huge amount since Windows 95 and this isn't utilised at all. We need a way of using the hardware to do our UI rendering so that we can draw both 2D and 3D objects within our applications, without imposing too much on the software core of the OS.

Overview

Graphics

WPF replaces the slow GDI libraries by using DirectX as its UI drawing library. WPF is also intelligent enough to know about your hardware capabilities, falling back to the slower software rendering should it need to. WPF's DirectX rendering capabilities only work for Windows XP and Windows Vista and even then there is a catch. When Microsoft were thinking about Vista and "Indigo" (code name for the WPF project), they released a new specification for hardware manufacturers to follow, to accommodate the new interface. Therefore, if your video card didn't receive a patch after 2004, OR they haven't added this requirement, then you will only have software rendering capabilities.

That doesn't mean that Direct3D and OpenGL are defunct. WPF is an implementation and is not as fast as Direct3D. If you need to create some real-time, high resolution graphics package or game then WPF will not be the way to go. WPF does cater for 3D graphics, rotation, lighting, transformation etc, but it does not replace the abilities of the Direct3D.

Flexible UI components

Some of the web concepts have really given WPF so great ideas on how to improve the framework. These include:

  • Layouts are flexible to the width of the application.
  • Creating text documents similar to Microsoft Word are as simple as adding headings, paragraphs, tables with captions, images etc.
  • Create styles for controls and apply them across your application - much like skins in ASP.NET.
  • Data binding can be done at page level, rather than by each control separately.

Think about a list. A list, as a high level abstract is just a grouping of 1 or more items. That's it. Therefore, the current ListBox implementation is quite inflexible; you just have a bit of text for the description. If you work harder you could get an image in there as well, but ultimately, the ListBox is really a TextListBox.

An awesome example of the thinking behind WPF is that the ListBox has been totally redesigned to hold just about anything you want. If you want an image/text combination, you group the 2 together and add it to the list! Easy peesy. You might be surprised that a CheckBoxList doesn't exist - why? Because it is just a list of CheckBox controls - so why create a new control, when a ListBox with CheckBoxes in does the same thing!

Resolution Independence

When working off high resolution monitors, the pixel density is a lot higher. This means if 2 screens of the same size, but with different resolutions, display the same size window, the higher resolution monitor will show the window to be much smaller. I personally use a high resolution laptop, therefore my task bar is tiny. You can increase the size of your desktop by either:

  • Changing the font sizes
  • Changing the DPI settings (preferred)

By changing your DPI settings, the fonts remain proportionate to your screen.

The only problem is that applications built prior to XP didn't have to take this into account and therefore changing the DPI can make some windows look a little strange, whereas others (which have catered for it) remain relatively normal. In Vista, it uses a slightly different technology called bitmap scaling which intelligently stretches images and fonts to fill out the DPI setting.

Event Model Changes

The event notification model has changed as well, meaning that events can "bubble" up to parent containers if needs be.

Navigation support

Users are getting more and more familiar with the navigation of web pages - a step by step approach to using sites. The WPF team have created page based navigation too, with page history. This allows users to create a similar navigation system to that of web pages, but from a user interface.

Summary

There are many many many more exciting features that WPF brings to .NET, and you will find huge books on the subject. Hopefully, I have given a small taster of the high level features available to you and in the future, I will try and provide some samples of what it can do.

Tags:

WPF

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar