It's been a long road to the Windows Presentation Foundation.
I learned to program Windows from Programming Windows 3.1, by Charles Petzold (Microsoft Press). In those days, programming for Windows was about windows, menus, dialogs, and child controls. To make it all work, we had WndProcs (window procedure functions) and messages. We dealt with the keyboard and the mouse. If we got fancy, we would do some nonclient work. Oh, and there was the stuff in the big blank space in the middle that I could fill however I wanted with the graphics device interface (GDI), but my 2D geometry had better be strong to get it to look right, let alone perform adequately.
Later I moved to the Microsoft Foundation Classes (MFC), where we had this thing called a "document," which was separate from the "view." The document could be any old data I wanted it to be and the view, well, the view was the big blank space in the middle that I could fill however I wanted with the MFC wrappers around GDI.
Later there was this thing called DirectX, which was finally about providing tools for filling in the space with hardware-accelerated 3D polygons, but DirectX was built for writing full-screen games, so using it to build content visualization and management applications just made my head hurt.
Windows Forms, on the other hand, was such a huge productivity boost
and I loved it so much that I wrote a book about it (as did my coauthor).
Windows Forms was built on top of .NET, a managed environment that took a
lot of programming minutiae off my hands so that I could concentrate on
the content. Plus, Windows Forms itself gave me all kinds of great tools
for laying out my windows, menus, dialogs, and child controls. And the
inside of the windows where I showed my content? Well, if the controls
weren't already there to do what I wanted, I could draw the content
however I wanted using the GDI+ wrappers in System.Drawing
, which was essentially the same
drawing model Windows programmers had been using for the past 20 years,
before even hardware graphics acceleration in 2D, let alone 3D.
In the meantime, a whole other way of interacting with content came along: HTML. HTML was great at letting me arrange my content, both text and graphics, and it would flow it and reflow it according to the preferences of the user. Further, with the recent emergence of AJAX (Asynchronous JavaScript and XML), this environment gets even more capable. Still, HTML isn't so great if you want to control more of the user experience than just the content, or if you want to do anything Windows-specific, both things that even Windows 3.1 programmers took for granted.
More recently, the Windows Presentation Foundation (WPF) happened. Initially it felt like another way to create my windows, menus, dialogs, and child controls. However, WPF shares a much deeper love for content than has yet been provided by any other Windows programming framework.
To support content at the lowest levels, WPF merges controls, text, and graphics into one programming model; all three are placed into the same element tree in the same way. And although these primitives are built on top of DirectX to leverage the 3D hardware acceleration that is dormant when you're not running the latest twitch game, they're also built into .NET, providing the same productivity boost to WPF programmers that Windows Forms programmers enjoy.
One level up, WPF provides its "content model," which allows any
control to host any group of other controls. You don't have to build
special BitmapButton
or IconComboBox
classes; you put as many images,
shapes, videos, 3D models, or whatever into a Button
(or a ComboBox
, ListBox
, etc.) as suit your fancy.
To help you arrange the content, whether in fixed or flow layout, WPF provides container elements that implement various layout algorithms in a way that is completely independent of the content they're holding.
To help you visualize the content, WPF provides data binding, control templates, and animation. Data binding produces and synchronizes visual elements on the fly based on your content. Control templates allow you to replace the complete look of a control while maintaining its behavior. Animation brings your user interface control to life, giving your users immediate feedback as they interact with it. These features give you the power to produce data visualizations so far beyond the capabilities of the data grid, the pinnacle most applications aspire to, that even Edward Tufte would be proud.
Combine these features with ClickOnce for the deployment and update of your WPF applications, both as standalone clients and as blended with your web site inside the browser, and you've got the foundation of the next generation of Windows applications.
The next generation of applications is going to blaze a trail into the unknown. WPF represents the best of the control-based Windows and content-based web worlds, combined with the performance of DirectX and the deployment capabilities of ClickOnce, building for us a vehicle just itching to be taken for a spin. And like the introduction of fonts to the PC, which produced "ransom note" office memos, and the invention of HTML, which produced blinking online brochures, WPF is going to produce its own accidents along the road. Before we learn just what we've got in WPF, we're going to see a lot of strange and wonderful sights. I can't tell you where we're going to end up, but with this book, I hope to fill your luggage rack so that you can make the journey.
The good news is that you will not be traveling alone. In the period between the first and second editions of this book, a large user base has sprung up, providing all kinds of information and real-world applications to inspire you. A tiny sampling of the best of this information is listed here:
Tim Sneath's big list of great WPF applications: http://blogs.msdn.com/tims/search.aspx?q=%22great+wpf+applications%22 (http://tinysells.com/114)
Tim Sneath's big list of WPF blogs: http://blogs.msdn.com/tims/articles/475132.aspx (http://tinysells.com/115)
Karsten Januszewski's Five-Day Course for Hitting the WPF Curve/Cliff: http://blogs.msdn.com/karstenj/archive/2006/06/15/632639.aspx (http://tinysells.com/116)
Microsoft's WPF community site: http://wpf.netfx3.com
The MSDN WPF home page: http://msdn2.microsoft.com/en-us/netframework/aa663326.aspx (http://tinysells.com/117)
CodeProject's WPF section: http://www.codeproject.com/wpf/ (http://tinysells.com/118)
thirteen23's inspirational set of WPF lab experiments: http://www.thirteen23.com/labs.html (http://tinysells.com/119)
Lee Brimelow's set of WPF designer tutorials: http://contentpresenter.com
âChris Sells
As much as I love the designers of the world, who are going to go gaga over WPF, this book is aimed squarely at my people: developers. We're not teaching programming here, so having experience with some sort of programming environment is a must before you read this book. Programming in .NET and C# is pretty much required; Windows Forms, XML, and HTML are all recommended.
Get Programming WPF, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.