Chapter 19. Windows Presentation Foundation

The Windows Forms techniques you learning in Chapter 18 are great, and they represent a major improvement in user experience over the console applications you’ve used for most of this book. Time and familiarity have a way of changing expectations, though, and Windows Forms have been around for a very long time in programming years. As rival operating environments grow and mature, and people become accustomed to sophisticated interface design on the Web, users’ expectations for interfaces have changed. Although Windows Forms are powerful, they don’t leave a whole lot of flexibility for designers to show off, and those designers who do try need to be programmers as well if they want to get the most out of Windows Forms. Microsoft has responded to those concerns with the Windows Presentation Foundation (WPF).

The purpose of WPF is to provide a solution that’s similar to the Windows Forms techniques you just learned, but provides greater flexibility of design. In Windows Forms, you used the visual designer to create the layout of the form, but you kept the code in a separate part of the file. WPF keeps the idea of separating the presentation (the look of the form) from the implementation (the event handler code), but it gives you direct control over the presentation. Instead of allowing access to only the Design view of your form in a visual interface, WPF represents the design in a form of XML, specifically created for WPF. This form of XML is called the XAML (pronounced “ZAM-el”), which stands for eXtensible Application Markup Language.

Tip

If you’re familiar with ASP.NET, this XAML idea will sound familiar to you. WPF borrows the ASP.NET idea of having a markup file and a code-behind file, except the markup is in XAML instead of HTML. Using XAML gives the markup greater flexibility over HTML, but you lose the familiarity that many web developers have with HTML. If you’re not familiar with ASP.NET, don’t worry about it. You don’t need to know ASP.NET to understand WPF; just know that the idea is similar.

Using XAML to define the presentation of your application opens up all sorts of design possibilities that Windows Forms just aren’t capable of. You may have already seen some of the possibilities in the Aero interface that Windows Vista uses, with its animated menus and transitions, and semitransparent “Glass” appearance. The WPF elements, though, go beyond the standard Windows controls.

Even more significant than what you can do with WPF is how you can do it. XAML is robust enough that you can define some event handlers (called triggers) entirely within the XAML, without writing formal handlers for them at all. In this chapter, you’ll start out very simply with a Hello World application to get the hang of using XAML. We’ll also show you how to use animations and some of the other elements, and finish up with a more elaborate application that displays data interactively.

Warning

To complete the examples and exercises in this chapter, you’ll need to have WPF on your machine. WPF is already installed on Windows Vista, and it’s available for Windows XP Service Pack 2 by downloading the .NET Framework 3.5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset