Check if Code is Executed at Design Time

Sometimes it is important to prevent certain code being executed at design time.

public static bool IsDesignTime
{
  get
  {
    return (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime);
  }
}

In WPF applications the following code can be used instead:

public static bool IsDesignTime 
{
  get 
  {
    System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject());
  }
}

 

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.