Friday, February 13, 2009

Initial Thoughts on WPF

I've started work on a quick-and-dirty little application for our church treasurer, who wants to be able to email donation statements to members, rather than send them via increasingly expensive snail-mail each quarter. I've written more WinForms apps than I can count, so I thought I'd try this one using Microsoft's still fairly new Windows Presentation Foundation. What you read on the MSDN website is that WPF is the hottest thing ever, and they give sample shots like this to whet your appetite.

Granted that I'm still at the very beginning stages of learning WPF, I wanted to give my first impressions. So some thoughts:

  1. Technically, it sounds really cool. I like the fact that, unlike GDI+, it's able to use hardware acceleration, with all the cool 3D potential that implies.
  2. I'm not sure about XAML yet. I'm not a huge fan of having to learn a proprietary markup language. Still, declarative programming? Interesting. Inability to debug anything I write? Interesting in an entirely different sense.
  3. It's a huge change from WinForms. Learning WPF is like learning ASP.NET: it's a completely different model. Don't expect to be able to pick it up in a few days.
  4. The UI design tools in Visual Studio are regrettably slow and clunky. I've got a fairly beefy machine, and it still takes several seconds to load up a very basic window in design view, with almost no controls on it. About every other time I switch to the design window, it tells me that I need to click on a special ribbon for it to refresh, because something (I have no idea what) has changed.
  5. The bundled controls are uninspired and uninspiring. To take just one example, for some astonishing reason, WPF has gone through three iterations, and it still doesn't come with a datagrid – which is perhaps the most basic control required in any business app. There are several third-party grids available, and MS has just released a "WPF Toolkit", which does have a basic datagrid. But still. It doesn't give me a lot of confidence that MS actually expects anyone to use this yet.
  6. There's a ton of inconsistency between the different UI controls. For instance, if you want to specify the text of a menu item, you set the Header attribute, like this:

    <MenuItem Header="Menu Item 1"/>

    But if you want to specify the text of a button or of a textbox, you specify it in the content area of the tags:

    <Button>Sample Button</Button>
    <TextBox>asdfasdfasdf</TextBox>

    But then get this. If you want to set the text of the button in code, you set its Content property:

    sampleButton.Content = "Content for a button";

    But if you want to set the text of the textbox, you set its Text property.

    sampleTextBox.Text = "Text for a textbox";

    Was there really nobody inside Microsoft who thought, "WTF?" MS has boasted any number of times that since they started from a clean slate with WPF, they got the design right. I can't yet speak for the overall elegance of the design, but if they can't even get the simple stuff right – consistent names and property accessors, for instance – it doesn't give me a lot of hope that they nailed the big stuff.
  7. The documentation isn't up to Microsoft's standards. It's there, and it's technically correct, but it's not terribly helpful. A good example is the official documentation for the Hyperlink.RequestNavigate event. Take a look at the page. It has, well, all sorts of vaguely interesting information. But it's entirely useless for someone who wants to understand the context for this event. When is it fired? Why does it exist? How do you use it? (Or the question I'm trying to troubleshoot at the moment, why does it not seem to be firing for me?) Compare that page to the documentation for a similar topic in ASP.NET, the Button.Click event. That page has a brief explanation of the context in which the event occurs, sample code in two languages, and links to four different articles for more information. Presumably the improved documentation will come with time. But it's not there yet.

I'm glad that Microsoft continues to improve their technology. But Microsoft also has a tendency to hype a particular technology, only to abandon it more-or-less completely within a few years. Anybody remember DNA? Or DAO? Or RDO? I don't think WPF is the same: it's more like ASP.NET vs. ASP: the underlying technology change is that significant. But unlike the migration to ASP.NET, the initial benefits of migrating to WPF are less clear to me.