WPF Reflections:

Controls

May 22 2008   11:33AM GMT

WPF Controls - how to avoid designer nastiness



Posted by: Mark Shurmer
WPF, Controls, XAML

Have you ever written any user controls or custom controls?
The difference between them is that with a custom control you have full scope to render it (plus you have to do it), whereas a user control is a container to amalgamate other controls.

With both of them though, you need to make sure that any calls made out of them are minimised.

Why?

Well because when they are created in WPF designers like Visual Studio 2008 or Expression Blend, they will be instantiated and therefore constructors will be called.
If you have calls out to databases etc, you will get a nasty looking exception thrown, or just the Visual Studio 2008 problem loading display:

blog-22may2008.JPG

How do you sort this problem?

By using the GetIsInDesignMode static method of DesignerProperties, like so
if (!DesignerProperties.GetIsInDesignMode(App.Current.MainWindow))
// do something you don’t want to appear in designer

May 16 2008   4:52PM GMT

WPF Controls



Posted by: Mark Shurmer
WPF, Controls

As I am architecting a new Line Of Business system for a customer, one of my thoughts is to recheck the situation with WPF controls.

The power and styleability of WP, with a few small exceptions, means that there isn’t quite the need for third party control libraries as there was in WinForms. In the days of WinForms it was a question of which of the main control libraries you picked, and how that was achieved with whatever ridiculous purchasing system was in place.

Now with WPF (and Silverlight soon), the focus has changed. There are a couple of holes in the WPF offering, like a paging grid, date time picker, numeric value editor. However, if you look at codeplex, most of the holes have been addressed by free controls. Also Xceed moved the goalposts for the component writing companies by giving away a top quality grid.
However, it’s not beyond some development teams to write their own controls as well - whereas that would have been a long, frustrating and expensive process in Winforms. I know because I have seen it :-(
Another bad effect I see, is that some companies just won’t bother - and try to muddle through on their own , which does seem a mistake to me.

What does that mean for the major component vendors?
Well, in my opinion, it means they need to up their gameplan, and provide components on a different level. They can’t just provide decent grids and toolbars etc, that were missing from Visual Studio.
To be fair we have started to see the beginning of that, with carousels and ribbons