apocryph.org Notes to my future self


What the HELL is wrong with WPF?

This weekend I’ve been working on one of my many self-edification projects, and against my better judgment I was implementing it with .NET 3.0/Windows Presentation Foundation, mainly because of the markup-like UI model which fit nicely with a few of my project’s idioms.

Anyway, I wanted to get a quick hit this weekend to keep momentum going, so I thought I’d put together the rich text interface of the project first. This should be stupid-easy, since WPF contains a RichTextBox class that does everything you could ask for with rich text, and the underlying content model is itself a XAML document, a FlowDocument. Too easy.

Unfortunately, RichTextBox doesn’t ship with the standard rich text toolbar, for doing things like bold, italics, etc. No problem; WPF has a toolbar element too. I wired up a bunch of buttons, each using the standard icon for its corresponding function, and set the buttons to invoke WPF commands like EditingCommands.ToggleBold, which the rich text box knows how to handle. “Wow”, I thought to myself, “this WPF thing isn’t half bad!”.

Then I noticed something. When commands are disabled (for example, the ‘Cut’ command is disabled when there’s nothing to cut), the toolbar button doesn’t respond to mouseovers or clicks just like a disabled button wouldn’t, but the icon on the button isn’t grayed out like one would expect. Then I tried something simpler; I created a Button with an Image in it, and explicitly set the Button‘s IsEnabled property to false. Sure enough, the image was still not grayed out.

Then I used Microsoft Expression Blend (a tool about which I could write a whole stream of angry rants) to show me the built-in XAML template for the Button control. Imagine my surprise when I discovered the only logic in the template that deals with rendering the disabled button is setting the foreground color to gray. That’s _it_. No wonder, then, that my images weren’t rendering differently; the foreground color has no effect on images.

You can see for yourself. Type this XAML code into XamlPad and see what happens:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    <StackPanel HorizontalAlignment="Left">
            <TextBlock>This button is enabled
                <Image Source="http://apocryph.org/themes/apocryph/logo.png" Width="32" />
        <Button IsEnabled="false">
            <TextBlock>This button is disabled
                <Image Source="http://apocryph.org/themes/apocryph/logo.png" Width="32" />

You’ll see two buttons, one with grayed-out text, but both with the same fucking image.

So let’s ponder this a moment. Back in 1995, I got my first copy of Visual C++ for free from a guy named Mike Strock (this was back when companies sold compilers for an outrageous sum, and thus I couldn’t afford them). One of the kickass features that blew me away was the MFC document/view model, where toolbar buttons mapped to commands, and would automatically disable themselves if the commands were disabled. Somehow, MFC automatically grayed out the toolbar button icons as well. It was incredible. “Surely”, I thought, “programming can’t get any easier than this”.

Apparently, I was right, coz here we are, 12 long years later, and we’ve taken a huge fucking step backwards. Now, don’t get me wrong. Using WPF I can easily make a button which contains a spinning 3D cube playing videos on each face that turns green when the mouse goes over it, all without any C# code. Unfortunately, no one would ever want to do that, while it’s easy to imagine a situation wherein you’d want toolbar icons to gray themselves (like, I dunno, every Windows application ever made).

This gives me a great startup idea. I’ll found a company in some tort-free jurisdiction like Costa Rica, called “FuckIt, Inc”. We’d offer an exclusive “Fuck This Shit(tm)” package, wherein programmers who can no longer bear the absurdity and kludge which is modern software engineering would be cryogenically frozen in a bunker on a secret island off the coast, to be revived 100 years hence or when the software industry gets its head out of its ass, whichever comes first. One of the test cases used to determine if the industry has its head out of its ass yet would be this one:

Using the latest development tools from the vendor of the most popular desktop operating system on the planet, is it easier to create toolbar buttons with icons that automatically disable themselves when the action they correspond to is disable, or to create a huge button containing a spinning 3D cube with video playing on each face? If the answer is the latter, as it is today, then the programmers stay frozen.

UPDATE: I’ve got a couple of solutions, here. Neither of them are optimal, but then, neither is life itself.

Comments (27) Trackbacks (0)
  1. ROFL – you described how I feel on a daily basis with the preposterous head in ass bs of a certain company

  2. OMFG! you are dead spot on mate! You just blurted out the words from my mouth. This is EXACTLY how I feel and I imagine quite a lot of developers feel the same way. I don’t know what Microsoft is thinking when it releases such technology every 2 years. I have been trying find a single decent tutorial on XAML, WPF and LINQ for the past week and believe me I could find anything other then a load of cow dung with shit loads of BS.

    99% of the examples / tutorials consisted of an insanely large button with 3d graphics on it. Now who in the fucking right mind would want to do such a thing. I am guessing those people who have there heads so far up their ass that they can see have a social party in the ass since Microsoft too is in deep penetration of the ass. I mean SERIOUSLY? What the fuck man! Win forms were a beauty, then why the flying fuck you want to release something ENTIRELY different and say that its the way forward especially when winform isnt broken. I mean why fix something when its not broken.

    I am so sick of MICROSOFT and their policy of shoving their crappy pieces of junk software down our throats. They know people are smart and don’t want their shit, so they start issuing threats of dis-engaging old software unless you buy the new one. FUCKING WANKERS!!!

  3. Ditto, ditto. Every day i discover another little doggy-doo from Microsoft. Like the lack of OLE support in .NET. Like the 8k row limit in SQL Server. Like the 8k limit on parameters in SQL Server. Don’t get me started on SQL Server. Like the stupid chrome theme of the WPF buttons that means they don’t behave like other WPF controls and require hideous hacking to customise. Like the stupid ScrollViewer that expands to the size of its content unless you hold it sideways on a Friday. LINQ. What the heck is that?!? I struggled for hours to populate a combobox in WPF with LINQ, then suceeded in minutes with good old ADO. Ah, the list goes on..

  4. On balance I think WPF is an improvement over WinForms, but the little gotchas and huge functionality gaps (editable grid, anyone?) almost make me want to go back to the WinForms days. Almost.

  5. If you don’t like it, don’t use it! You can still use Win Forms…or you can use Java and skip Microsoft all together. Yeah, WPF is a pain in the ass a lot of the time, but no one at Microsoft is forcing me to use it. Once you get the hang of it it’s actually nice to work with.

  6. Of course there’s not a gun to my head demanding I use it, but if one mustn’t complain about software unless one’s life depends upon using it, then whole swaths of the Internet lose all legitimacy!

    WPF is the next evolution in the MSFT GUI toolchain, and as such Windows programmers have little choice but to embrace it, it they want maintenance, tool support, and jobs. It seems reasonable to rant about the aspects of WPF that I hate, particularly when they seem due not to carefully considered design decisions but rather sloppy implementation.

  7. With great power comes great responsibility. If you change the background color, then surprise! All that changes is the background color – duh. You’ve got the power to put pretty much anything inside anything else, including buttons which is power you could only dream of in MFC where you got to stick precisely one thing in the standard button – text. But with that power comes the fact that WPF isn’t going to know what you want to do when you start putting miscellaneous stuff in buttons. So spend a few minutes to make an animated effect that slowly grays out whatever your button content is, make it a default button style and marvel at the fact that the effect automagically happens to all your buttons and looks WAY better in anything you could have achieved in MFC in less than a week of effort.

  8. I fucking hear ya! I’m also struggling with this shit every day just to discover that MS – again – really went out of their way to accommodate every possibility imaginable but rendering the whole system/concept unusable on the way. Bravo!

  9. Three months later, and over on The Code Project, Tamir Khason has published a solution which works. It shows icons as disabled by setting Opacity=0.5 and does other clever things such as adding and configuring a new toolbar entirely through XAML.

    Hope this helps someone.

  10. Man, I feel the same.

    Remember the days of computers like Atari 65 XE or Amiga 500? How they could ever compute anything, if they had processors thousands times slower, and today I can barely do my job, because of the abstractions over abstractions of the programmers. But we DID work back then, w/o all those layers of absurd, and the use of computers were _faster_.

    What went wrong?

    Great piece, thank you.

  11. I´m brazilian I´have developed ERP software my whole life,This market in Brazil is still big,because of hour burocracy,laws change every day,and every year they create a new tax.
    I´m reading about WPF,and I´m not sure it is suitable for ERP development.
    In ERP forms are not so dynamic,I would like the users to see the form the way I designed it,Imagine how dificult it would be to give support if every costumer have a different screen?
    All I saw until now,was very stupid WPF ERP systems,where all data entry was made by using grids,this is not what happens in real life,I prefer the Tabs full of data-bound controls approach.
    I´m not a WPF criticizer ,In fact I know almost nothing about the technology,but I really didn’t like what I saw until now.

  12. WPF is a joke, but we are stuck with it. Just like .not

  13. Try using MVVM pattern with WPF, you will see that everything will fit. You get all this “gotchas” because you are using WPF wrong, it was not meant to be used like win forms, learn MVVM!

  14. MVVM has nothing to do with this problem. The nature of the complaint is that WPF has no straightforward way of rendering buttons in a greyed-out style which is universally recognized as indicative of a disabled UI element. Using MVVM I could more easily bind a “IsEnabled” property on the model to the assorted trickery I ended up using to make the button appear disabled, but the fact remains that this is manual trickery which must be repeated every time one requires this capability. That’s stupid.

  15. I’ve been doing WPF and MVVM for a good year now, and I’ve done every kind of win-programming and I can say with certainty that although WPF makes certain functionality magically easy, in the end once you breach a certain complexity level, the whole application becomes magically hard to work with. I want to say the problem is that the platform is really in it’s infancy considering the scope of features. However I’m afraid the problem is quite a bit deeper then that. It’s all about politics and the bottom line in the end. I also happen to know a guy that was one of prime architects behind WPF, and guess what, he is at Google now.

  16. It is really ridiculous. One of the hall marks of the wysiwig interface is that it hides detail from the user so the user does not have to type in commands like:
    C:\DIR *.cs >> listOfcs.txt.

    So why in the HELL did MS give us such a crappy, shitty, un-usable interface in WPF? I mean, you have to learn a whole now paradim just get a fucking menu up on the app. I mean really, what was so bad about the win forms interface in the IDE? Your stupid WPF development team never user Visual Studio? What the hell are you people smoking? Are you really so damn rich that you think you can do no wrong? Or did you just fall apart after Mr. Bill left? I will say this, if a viable acceptable alternative to MS comes along I will serously consider it.
    Developer defection is something that you idiots at MS are going to see, and a lot of it if someone comes out with a tool set that is usable under Windows.
    Hell, I might even switch to programming Mac and iPhones. At least Apple is not stupid enough to break a good development environment just to accomodate a ‘new, flashy, hyped to death’ technology that makes programming about 10 times harder…

  17. As for you marius, I know all about MVVM as I’ve been using silverlight for going on two years.
    The form oriented development environment has NOTHING to do with the MVVM model, nothing at all. You can write a damn MVVM app using stone knives and bear skin (C++) just about as easily as you can with WPF. The interface to building user interface components has absolutely nothing to do with the type of paradim that you are using behind it.
    It looks like to me like MS went and built WPF and all of it’s components and then someone said “ge, how are we going to code the interface?” and they hacked it. Plain and simple, in order to ship the product they compromised on the most heavily use component in the entire WPF environment; the damn thing you use to design it!
    Oh yeah; do you build the interfaces between the presentation and your services? Or do you let the IDE do it for you. If you don’t build it and let the IDE do it for you it puts a whole lot of un-necessary crap in there that will slow your network down and move a whole lot of un-necessay objects, data, kitchen sinks, etc…

  18. 420, easy for you to say; bet you don’t have a manager saying ‘this is our new paradim and our development stategy will be based on WPF’.

    Sometimes we have to use a hoe even though we know we need a troy built tiller…

  19. In defense of MSFT, Apple’s XCode doesn’t hold a candle to Visual Studio in terms of power or flexibility. Visual Studio combined with R# is unmatched by any other toolchain IMHO.

  20. WPF is the future. It’s a big learning curve but worth it.

    Considering your comments: Microsoft did a good job on winforms :).

    In time WPF will beat winforms.

  21. You just need to use a ControlTemplate with an appropriate effect in the setter for IsSelected trigger.

  22. fucking shit unuseable aparft from graphics where you dont need ’em – waste of time and a massive step back apart from junk instantly obsolete book writers

  23. WPF/WCF completely useless!
    LINQ> Great – pretty much the only technologies recently released by Microsoft that actually helped me! (Linq to SQL, drag drop from Server Explorer VS automatically generates the data access objects … etc these are useful feature)
    WPF> So difficult to remember binding expressions and trouble shoot binding errors! I like tag based construction of user interface but just not everything needs be done “Declaratively”
    WCF> I have libraries that does chunking/compression/encrption/signing/custom authentication and permission – after using WCF for two years I still don’t know why the hell on the planet did I not just get this implemented in socket and skip the god damn learning curve.
    God damn M$ there are developers out there who’s just trying to get things done quickly.
    WCF/WPF – fuck reminds me how much time I wasted in highschool being forced to learn literature of various languages.

  24. Almost forgot – you know how much trouble it brings silverlight can’t use regular .NET libraries?!
    Fuck M$, well done

  25. So here i was thinking why do these effing WPF Labels not have the click event built-in like the Winforms Label?!!? (not just labels actually). and then i read this blog. hahah!

    Im going back to WinForms for now.

  26. Man.. you made my day. This may be an old post, but nothing changed in the last years. I am new to WPF and every day i have a new problem that never existed with WinForms. I am glad to know that i am not alone!

    Now i am searching for a solution for the problem described in this post. What some people call a solution is a shame. I don’t want a big bunch of code lines to solve something that should be handled by the system. And i don’t want to create a second grayscale image for every button in my application.

    People come up with solutions like that and believe that they did a really great job. And other people are happy with it! They’re all fucking idiots, when they don’t realize, that solutions like that are fucking workarounds and nothing more.

    I don’t understand MS. They wrote about .NET that it will make programming easier and they were right! But now they made several steps back. Simple things that i never had to care about before are extremely hard to achieve now. But now we can display spinning cubes on buttons, TreeViewItems, and i don’t know what else…
    Fucking important! I don’t know how i ever could live without something like that!!

  27. Where is the fucking like button????

Leave a comment

No trackbacks yet.