WPF Reflections

May 22 2008   11:33AM GMT

WPF Controls – how to avoid designer nastiness

Mark Shurmer Profile: MarkWPF

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.


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:


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

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: