Simple Talk is now part of the Redgate Community hub - find out why

5 Reasons why I hate WPF

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.

image_thumb.png

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.

<PathGeometry x:Key=”DatabaseShape”
Figures=”M 150,100
L 150,250
Q 150,280 225,280 S 300,280 300,250
L 300,100
Q 300,80 225,80 S 150,80 150,100
M 150,150
Q 150,170 225,170 S 300,170 300,150
M 150,200
Q 150,230 225,230 S 300,230 300,200″
FillRule=”Nonzero” />

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.

Conclusions

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.

How you log in to Simple Talk has changed

We now use Redgate ID (RGID). If you already have an RGID, we’ll try to match it to your account. If not, we’ll create one for you and connect it.

This won’t sign you up to anything or add you to any mailing lists. You can see our full privacy policy here.

Continue

Simple Talk now uses Redgate ID

If you already have a Redgate ID (RGID), sign in using your existing RGID credentials. If not, you can create one on the next screen.

This won’t sign you up to anything or add you to any mailing lists. You can see our full privacy policy here.

Continue