I decided to use writing a new tool as a way to learn WPF and MVVM and I thought I’d write down a few of my problems as a way of cathartic release.
I decided to read a book before attempting WPF for the first time as I’ve heard others complain about the steep learning curve. I chose the rather excellent “WPF 4 Unleashed” by Adam Nathan to read through and “Pro WPF in C# 2010” by Matthew MacDonald as a reference whilst I programmed.
1 – Poor editing support for XAML
The first thing I think any developer is going to notice about starting with XAML is that the visual studio designer is pretty poor (choosing my words carefully). I liken it to using the experience using Word to edit HTML documents. Really you have no choice but to hand code it if you want anything even roughly resembling something maintainable xaml. Even then the designer doesn’t give the best of previews e.g.
Why no scrollbars?
2 – Poor editing support for Graphics
Next up comes what is a strength of WPF, the vector graphics. Now don’t get me wrong I like vector graphics just the tool support at the moment is terrible. The only bright ray of hope is Inkscape which will allow you to trace a bitmap to convert it into vector and also export xaml files.
I found this helped somewhat but still the output wasn’t very clean and for simpler graphics like the arrow or the tick I just resorted to drawing on graph paper and typing the ever so user friendly PathGeometry directly.
Q 150,280 225,280 S 300,280 300,250
Q 300,80 225,80 S 150,80 150,100
Q 150,170 225,170 S 300,170 300,150
Q 150,230 225,230 S 300,230 300,200″
Yes, I coded this by hand.
3 – Blurry bitmap appearance
Now for another drawback when favouring vectors. I’m not a purist and am regularly accused of committing coding horrors however, Dear Microsoft, Please support just showing a bitmap at normal resolution without resorting to blurring it. I will get images and I can’t spend the time converting everything to vectors so sometimes I just want to show a bitmap without having to swallow a whole bottle of Kool-Aid.
It amazes me that WPF doesn’t include this ability as standard.
4 – Changing appearance of standard control
Is it a good or a bad thing that in order to change some relatively minor appearance of a standard control you have to copy the whole control template into your project and modify it? I really miss the ability to just change behaviour or appearance slightly with a cleverly constructed sub-class in winforms.
To me it just seems a little heavy-handed and I really hope there must be a better way of doing things that I’ve just not found in my initial investigation.
5 – Hard Trivial – Trivial Hard
I can’t remember the exact quote but it went something like.
“WPF makes the hard trivial and trivial hard”
If you want your application to contain lots of custom drawing, drop shadows, blended backgrounds and an almost CSS like way of designing the UI’s then WPF and MVVM is fantastic. However if you want to show a modal dialog box – beware!!! Why? I mean the Kool-Aid drinkers out there talk about lovely design patterns and clever ways to get around what to me is a very common requirement.
I did manage to bodge my way around it using a Callback a collection of ICommands and a ManualResetEvent. I even think it’s not that terrible a way of doing things although I’m probably wrong.
Is WPF all bad? No, certainly not. I think there’s a steep learning curve so reading a book before you start is a must in my opinion. However the clever databinding, MVVM and resource dictionaries make for a very testable way to program a UI. WPF takes away most of the rendering and re-painting that plagues me when I use winforms and is a blessing worth a fair amount of pain.
Is it right yet? I’m not sure but I’ll certainly play with it some more and see where my journey takes me.
I’d love to hear your experiences of WPF if you’ve tried it, and any solutions to some of my gripes above as I can’t believe I’m just not missing something fundamental.