Yanshof
Yanshof

Reputation: 9926

How to check if i'm in run-time or design time?

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.

Upvotes: 6

Views: 2939

Answers (2)

Jake
Jake

Reputation: 7783

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.

Upvotes: 4

Prince Ashitaka
Prince Ashitaka

Reputation: 8773

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

Upvotes: 11

Related Questions