RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Give Your .NET Apps the Face They Deserve with WPF

You've probably heard about Avalon (now Windows Presentation Foundation, or WPF), and maybe seen screenshots or a demo, but now you can try it out yourself. Get started building next-generation Windows applications now.

icrosoft first publicly demonstrated Avalon way back in 2003 at the Professional Developers' Conference (PDC) in Los Angeles. They touted Avalon as the next generation in user interface methodology, and it was well-received by developers and users alike.

Microsoft unveiled a more complete version of the project code-named Avalon back in 2003 at the 2005 PDC with its new and official name: The Windows Presentation Foundation (WPF). By that time, it had evolved beyond demoware into the beginnings of an alpha-release API. Now, a few months later, it is in the advanced beta stage—and you can get your hands on it and use it to build next-generation user interface applications.

But what is WPF, and why is it so important?

First, it is a clean and effective separation of user interface definition and application implementation. It allows application designers to design the visual aspects of a user interface separately from the developers who write the code that underpins the user interface. This is important on many different levels:

  • With the clean separation between the two, software development companies can have their designers concentrate on what they do best, while letting their developers support them
  • With the ongoing trends around outsourcing and offshoring, WPF makes it easier for local designers and business analysts to take on the designer role, mocking up a UI, and building basic functionality into it, while offshore coders can build the underlying logic separately, without interfering with the design.
  • It allows for easier application internationalization. Different, separate UIs can be tailored for different locales, but the underlying, separate codebase can be common across all of them
  • It allows for "white labeling" of products. This is a process which customizes the UI for different customers without forking the underlying logic. Developers can create the application logic, and then map different UIs to it for different customers, containing their branding, etc.
WPF achieves all this by using an XML-based language to define the user interface. This language is called XAML, which stands for XML Application Markup Language.

Second, WPF uses a vector-based instead of a raster-based drawing engine, which is a radical departure from earlier Windows drawing engines. Raster-based engines draw on the screen by painting pixels onto the rendering surface. Pixels are just dots; therefore, as screen resolution (DPIs, or Dots Per Inch) increase, the raster-based model tends to break down. As screens approach Ultra-high DPI resolution, fonts will have to have hundreds if not thousands of dots per inch to be readable. Consider the typical default setting of Microsoft Word fonts which is 12-point Times New Roman. While that works at common resolutions today it would be unreadable on an ultra-high DPI, high resolution monitor. Managing all these dots with raster-based imaging would require incredible processing power, and would ultimately be wasteful. However, taking a vector-based approach expresses fonts and other lines in a scalable coordinate system rather than in pixels, making them independent of DPI. Consider the difference in scaling between a Windows Metafile (WMF) and a Bitmap (BMP) image, and you'll see where this is going. Additionally, vector graphics allow for easier and faster manipulations transforms such as rotation, 3D, hidden line removal, animation and more.

But enough theory, let's start putting all this into practice, so you can start building your first WPF-based application to get a taste of this technology and what you can do with it.

Getting Started
Author's Note: WPF is betaware at the moment, and as such it's neither trivial to set up nor to get running. However, Microsoft has drastically improved its betaware, making life easier for early adopters, so you should be able to get up and running successfully if you follow the guidelines in this article.

First, I strongly recommend that you uninstall everything to do with WinFX, the Windows SDK and any other development betaware before you begin. Indeed, I think it is a good idea to even remove Visual Studio 2005 and the .NET framework 2 before beginning. You can try it with these pre-installed, but I have obtained the best results by starting with a completely clean machine. You might try all this out using a virtual machine image running in either Microsoft Virtual PC or VMWare Workstation. Second, before you begin, you should download, install and run the terrific 'cleaner' utility from CCleaner.com. This tool ploughs through your registry looking for bad, old or corrupt keys (the usual side effect of using betaware) and cleans them out. To get started with WPF, I followed this process, and everything worked cleanly, first time.

When you are ready, you should download and install this software in this order:

  1. First, you'll need the WinFX runtime components.
  2. After installing these, reboot—and if you don't have it already, you can install Visual Studio 2005. If you don't have a copy of this, you can use the free Express Edition.
  3. Next, download the Windows SDK—a huge download of about 1G. Note that with the SDK, one option is to download the IMG file and burn it to a DVD or load it into a virtual CD/DVD application and install it from there. Unfortunately, when I did this, the installation failed every time. So instead, I recommend that you download the IMG, and then download the associated Setup.exe (you'll find that download on the same page). Put both of these in a directory on your HD. Run the Setup.exe application and it will read the IMG file for you, and you can install successfully.
  4. Finally, you must install the Visual Studio development tools (codenamed 'Orcas') for WinFX development. These include the 'Cider' designer for XAML in Visual Studio.
  5. If you've gotten this far, you're now ready to start coding WPF applications, but one final download (and one well worth your time) is the Expression Designer for XAML.
As a developer you can use the Cider tool to build basic XAML user interfaces within Visual Studio.NET, in a manner that you will be very familiar with, as it is virtually identical to what you can do with the basic Windows forms designer. However, to start using some of the really slick features that XAML offers, I recommend that you explore the Expression Designer for XAML.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date