If you have not taken a look at Windows Presentation Foundation (WPF) yet, you really should. WPF is a great desktop development platform. Granted, all of the tools are not yet in place, but Microsoft is pouring millions of dollars into developing WPF tools. Microsoft now considers Windows Forms a legacy technology and they won’t update it within

Visual Studio. These two reasons alone should be enough to convince you that need to start learning WPF right now. While WPF offers a new set of development tools, you’ll see a lot that looks familiar. You still have the typical desktop controls like text boxes, check boxes, radio buttons, etc. You still write the same C# or Visual Basic code. The major difference is how you layout the screens, control the look and feel of the controls, and some of the properties are a little different. This article will give you a good introduction to what WPF is all about without diving too deep.

It’s All about the XAML

XAML is an XML-based language for describing user interface components such as text boxes, combo boxes, radio buttons, and so on. In addition, XAML is used to describe how to apply styles to these controls. Styles control settings such as width, height, color, etc. XAML is very similar to the way in which you declare controls in ASP.NET applications. If you are familiar with ASP.NET development, you should feel right at home with XAML.

Remember back when you did classic ASP applications? Remember mixing code and HTML together? Then remember when ASP.NET came out and how much easier it was to have a declarative syntax for controls? The same holds true for XAML. You no longer need to use procedural code in a partial class to create controls on a Windows Form design surface. Now you have a declarative syntax. Consider the following XAML to define a text box control.

<TextBox Name="txtFirstName" Width="100" />

The declarative nature of XAML has many benefits. It is compact compared to the many lines of code to declare the same text box within Windows Forms. It lends itself better to code generation. It allows for better portability from desktop to Web as this same code could be interpreted differently based on whether it is running within WPF or Silverlight.

“If you are familiar with ASP.NET development you should feel right at home with XAML.”

XAML is definitely the way of the future for desktop development and for rich Internet applications (RIAs), aka Silverlight. XAML is used for not only control declarations but for actions as well. You can use XAML code to express animation, graphics, data binding and multi-media. Using XAML will significantly reduce the amount of code you need to write when you need to employ these techniques in your applications.

Dynamic Styles and Themes

“Silverlight employs a smaller subset of the XAML language available in the desktop world, but it is still the same XAML syntax as WPF.”

In traditional Windows Forms applications, changing the look and feel required a lot of re-work, and a close bond between a programmer and a designer. WPF changes this traditional approach. A programmer can layout the basic controls in almost any haphazard fashion and get the code working. Then a designer can come in later and completely move the controls around, add color, graphics and any other elements, all without touching any of the back-end code.

You can create all of the styles, and even complete themes for a WPF application, as an external resource. This means you may change the look and feel of an application without re-compiling any of your code! This would be difficult feat with a traditional Windows Forms application.

XAML and Silverlight

As I mentioned before, Microsoft also uses XAML in Silverlight applications. Silverlight is Microsoft’s cross-browser platform that allows you to create rich Internet applications (RIAs) using the same declarative syntax that WPF uses. Silverlight employs a smaller subset of the XAML language available in the desktop world, but it is still the same XAML syntax as WPF. Microsoft’s release of Silverlight 3 will make even more XAML available than earlier versions of Silverlight supported. Silverlight 3 even lets you create out-of-browser applications.

Easy Separation of Business Logic and UI

Microsoft designed WPF from the ground up to loosely couple presentation and business logic. This architecture allows you to use design patterns like Model View Controller (MVC) or Model View View Model (MVVM) in your development. These patterns not only separate your business logic and UI, they also make it possible for you to unit test every line of code in your application. While you can get a separation of business logic and UI with Windows Forms, the hooks within WPF make this separation much easier.

Animation

While animation is not a prerequisite for many business applications, there are some areas where a proper (and typically short) animation can guide the user and make them aware of something on the screen that they might not otherwise notice. Animation such as this makes your application more user friendly and self-documenting. WPF makes doing simple animations very easy. In fact, a lot of times, you can express animation in XAML and you do not need to write any traditional VB or C# code.

Screen Resolution

Windows Forms applications can be hard to scale when a user's screen resolution changes. WPF has built-in facilities for handling different screen resolution similar to the way HTML works with screen resolution. However, just like traditional Window Forms or HTML, you can also layout screens incorrectly and end up with applications that do not scale on different screen resolutions. But, the capabilities to scale are built in to WPF.

Data Binding

I have never been a big fan of data binding. There have never been enough hooks for the things I am asked to do by my clients. Data validation always seemed to be an afterthought, or again, not enough hooks were in place to do what was necessary for business applications. With WPF, Microsoft provided much more robust data binding and many more hooks exist that allow the flexibility needed for complicated business applications. You will find yourself using XAML to express the data binding that you would have had to write code for in Windows Forms applications. This will increase your productivity immensely once you start to take advantage of these new techniques in WPF.

Community and Third-Party Support

Of course, no new development paradigm will catch on if the third-party vendors and the programming community at large are not behind the effort. There is a large community and many third-party vendors behind WPF. You will find tons of code samples at CodePlex.com and some indispensible tools such as the WPF Toolkit and the WPF Power Toys. Be sure to download these two add-ons for WPF as you will find some great controls that help you get your business applications programmed quickly. I find great value in the WPF DataGrid in the WPF Toolkit. Microsoft will roll the WPF DataGrid control into the .NET Framework 4.0.

Many third-party vendors have updated their control packs to support WPF. You will find many of your favorite controls that you used in Windows Forms applications have WPF counterparts. This will ease your transition from Windows Forms to WPF.

“There is a large community and many third-party vendors behind WPF.”

Resources

A Bing or Google search will yield many results when you search on WPF topics. You might also check out the Microsoft Patterns & Practices group who have developed guidelines for WPF development. You can find these at http://www.codeplex.com/CompositeWPF. You will find many code samples and training videos at http://windowsclient.net. The main home page for WPF on CodePlex (http://www.codeplex.com/wpf) will guide you to the WPF Toolkit and WPF Power Toys.

Summary

I can think of many more reasons than I outlined here as to why you need to take a good look at WPF as your desktop development platform. Many of the reasons are geared around the separation of UI and code that Microsoft has achieved with the XAML language, WPF, Silverlight, Visual Basic and C#. I hope you will find your way to WPF in the near future.