5

I developed some userControl that contain some information check on the 'IsVisible' method ( override method ).

When i using this usercontrol on some window - i see some error because the 'IsVisible' method look for some variable that is set on run-time.

How can i check if I'm in design time and the system is not running ?

Thanks for the help.

Yanshof
  • 9,659
  • 21
  • 95
  • 195

2 Answers2

10

DesignerProperties.GetIsInDesignMode(this); This would return true if you are in design-time.

Daniel James Bryars
  • 4,429
  • 3
  • 39
  • 57
Prince Ashitaka
  • 8,623
  • 12
  • 48
  • 71
  • 2
    There a mistake in this answer : you may want to call DesignerProperties.GetIsInDesignMode(d) which can be found in System.ComponentModel. Note that d must be an UIElement. This DesignerProperty is an attached property. – GameAlchemist Nov 11 '11 at 18:55
4
public partial class MainWindow : Window
{
    public MainWindow()
    {
        if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            Console.WriteLine("The main window is in design mode.");
    }
}

The other answer is technically correct but I am providing this one to clarify the namespace and the usage.

Jake
  • 7,565
  • 6
  • 55
  • 68