Often times when trying to view a Window or UserControl in the WPF designer, the designer chokes and pukes all over your screen. Though your first instinct may be to abuse the Cider designers please refrain. Belive it or not it may be possible that it is not their fault! As it turns out, when Cider attempts to render your Window or UserControl it runs through a somewhat abbreviated version of its lifecyle. If you have code in any of these framework methods that, say, calls a web service or hits a database, Cider may not be able to resolve all of the resources needed. Sadly like many things in WPF the error messages are not always that helpful.

Thankfully there is a method in the System.ComponentModel namespace that can help.

private void Control_Loaded(object sender, System.Windows.RoutedEventArgs e)
    if (DesignerProperties.GetIsInDesignMode(this))


Calling this method will return a boolean indicating weather or not the current control is being rendered in the designer or not. You can use this to wrap code that could potentially choke up the designer. Though this is not a perfect solution in terms of keeping your code clean. It will allow you to view your Windows or UserControls in the designer. And in many cases that is a must.

Tagged ,

3 thoughts on “GetIsInDesignMode(this)

  1. spsuthar says:

    Thanks!! This is really helpful.

  2. You could not be more right…

  3. website says:

    At least some bloggers can still write. Thank you for this writing!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: