Home About Eric Topics SourceGear

2006-06-05 12:00:00

WPF for Laggards

Recently I was annoyed to discover that Charles Petzold does not have an imdb record.  Since he is not an actor, I guess that makes sense, but a part of my subconscious mind expects that all big-name celebrities will have a record on imdb.com.  Besides, imdb lists plenty of other celebrities who are not really actors, including Bruce Springsteen, Dan Marino, and William Shatner.  Why not Charles Petzold?

And why was I looking for Petzold on imdb?  Well, I often check imdb when I want to find out how old someone is.  A week or two ago Chris Sells described Petzold as "one of this generation's best technical writers" (italics mine).  My immediate reaction was that Chris was flattering Petzold not once, but twice.  I mean really.  Wasn't the first edition of Programming Windows published back in the eighties when I was in high school?  How could Petzold be considered a part of the same generation as Chris and I?

Anyway, all this got me thinking.  Petzold is currently writing a new book about WPF ("Windows Presentation Foundation", formerly code-named "Avalon"), the next-generation Windows API for graphics and user interfaces.  But I don't know anything about WPF!  If a man of his advancing years is still learning new technologies rapidly, then what's wrong with me?  I'm not old enough to be a laggard yet.  I like to think of myself as an early adopter.

But the fact is that WPF is in beta 2 now.  All the cool early adopter people have been working with this technology for quite a while.  It's time for me to get a clue, especially if I want to have any chance of impressing other geeks with my technical knowledge at TechEd in June.  :-)

So, just as I used to cram for my exams in college, I've been trying to digest as much WPF knowledge as possible in a very short time.  And I thought perhaps if I wrote down my first impressions of this technology it might be helpful for other laggards like myself.

Ten Things to Know About WPF in June 2006

1.  It's part of WinFX.

Since around 1995, the primary API for Windows development has been Win32.  Sometime in the next year or so, that will change.  The new API is called WinFX.  WPF is just one part of it.

If you remember the transition from 16-bit Windows programming to Win32, it helps to think of this transition in a similar way.  This is a very fundamental shift.

Back when .NET was introduced, Microsoft gave us managed code, a new way of developing for Windows.  Now, with WinFX, managed code is no longer just another way of developing for Windows, but rather, it is THE way of developing for Windows.  WinFX completes the transition started by .NET, the transition to managed code.

People have been wondering for years why the .NET runtime components are not a required upgrade in the Windows Update service.  I don't know why, but if I had to guess, I would say that the WinFX runtime will be a required update.

2.  XAML is like HTML.

XAML is a markup language.  It is associated with WPF, but strictly speaking, the two are independent.

It looks to me like a major goal of WPF is to blur the line between web development and desktop development.  For users, WPF wants web applications to be more like desktop applications.  For developers, WPF wants desktop applications to be built more like web applications.  It is for this latter reason that XAML was born.  XAML is a markup language which can be used for setting up WPF user interfaces.

Right now, XAML doesn't feel like HTML to me, but maybe it will when I get more up to speed.

3.  There is no HWND.

This one is kind of weird if you think about it.  I learned Win32 programming without a framework, so HWND and WndProc are old friends for me.  Since then I've used higher level frameworks like MFC, wxWidgets, and Windows Forms.  Each of these frameworks tries to hide HWND, keeping it out of sight lest its ugliness cause public embarrassment.  But under the layers of abstraction, HWND is always there.  In WPF, it's not.

When WPF first came out, people said it is not built on top of Win32.  Now I understand what they meant.  WPF is not another abstraction layer on top of the core Windows API.  It is something else entirely.

So what is WPF built on?  It's a very high-level API, so it has to be built on top of something, right?  The answer is that WPF is built on DirectX, and if you've never really thought about the fact that DirectX is not built on Win32, now would be a good time to just sit down and think it all through.  :-)

4.  The "Cider" isn't ready yet.

There's an early preview available of a tool which allows visual development of WPF user interfaces in Visual Studio.  Its code-name is "Cider".  Don't bother with it.

I have no doubt that eventually Visual Studio will offer outstanding support for WPF.  But right now, it's just too early to even try to use this thing.  Rather than get your hopes up, just don't even install it.  Face the fact that WPF development today requires you to use your keyboard.  You can still use Visual Studio of course, but you'll be typing XAML and C# code rather than having a visual UI designer create it for you. 

If that's unappealing to you, then you might want to just wait.  Personally, I kind of like the idea of learning WPF without the visual tool.  It's good to know how things work under the hood.

5.  XAML Cruncher is Neato.

For early experimentation and learning of XAML and WPF, try XAML Cruncher, a utility by Charles Petzold.  It's a two-pane app:

The right pane gets refreshed every time the left pane changes, so it feels very instantaneous.  You can grab chunks of XAML from various places and paste them in.

6.  Chris Sells' book is good.

Petzold's book will probably end up being the definitive work.  But the book by Chris Sells and Ian Griffiths is available today, and it's very good.

7.  You can use Windows XP.

WPF is usually associated with Windows Vista, the next major release of the Windows operating system.  But if you want to do development with WPF now, you don't have to be using Vista.  Just install the latest versions (beta 2) of two things:

If you want the easiest possible start, just install the runtime components and play with XAML Cruncher.

8.  But you have to use IE.

I'm a Firefox user.  When I started fiddling with WPF, stuff just wasn't working.  So I was sad.  :-)

WPF is supposed to offer some very cool new forms of "web applications".  I haven't figured out the fine points and distinctions yet, but if you think about Java applets and Flash and SVG and ActiveX and Ajax, WPF has some stuff that is trying to solve the same set of problems.  (For WPF, the buzzwords seem to be ClickOnce and Express.)

And it's really quite cool.  On Petzold's blog is an entry about an all-XAML clock.  If you have the WinFX runtime components and you click on the link in that blog entry, you'll get a nice analog clock in your browser window.  Resize the window and the clock resizes cleanly.

It's easy to imagine how this technology could move beyond demos like a clock and be used for real applications running in a browser with truly rich user experience.

But it doesn't work in Firefox.  Hopefully someday it will.

9.  Rod Paddock is right.

Previous jokes aside, anybody using WPF today is a very early adopter.  I'm no expert, but I would have to agree with Rod Paddock when he says that WPF is not ready for prime time

WPF shows us a very interesting future for Windows developers, but the key word here is "future".

10.  There is no Windows Telephony Foundation.

In the last few years, Microsoft's habit has been to replace great code names with incredibly mediocre official names.  Avalon was a great name.  Windows Presentation Foundation is, well, less than memorable.  In its abbreviated form, WPF, I suppose it's not so bad.

Note that the WPF acronym was part of a set.  Along with WPF they announced WCF (Windows Communication Foundation) and WWF (Windows Workflow Foundation).

But alas, every time I see that set of abbreviations, it makes me wish they had included a new API with a T in the middle, like Windows Telephony Foundation.  :-)

PS

Aha!  Wikipedia came to the rescue:  Charles Petzold is 53, younger than I thought, and definitely not old enough to be my dad.  I suppose that means that he and I actually are of the same generation.  :-)