Design Time Check for WPF and Silverlight
Do you commonly check whether code is being run in Blend or in the Visual Studio design surface? Often times, this is necessary to load up sample data or to prevent code that could potentially break the “Blendability” of a WPF or Silverlight app.
In WPF, you can call the DesignerProperties.GetIsInDesignMode for it. In Silverlight, you can check for HtmlPage.IsEnabled property.
I check for design mode often and needed a simple, consistent method to mask the DesignerProperties call in WPF. In Silverlight, I wanted to hide the hacky HtmlPage.IsEnabled check and change it from being a not(!) check to a positive check. Also, when Silverlight support the DesignerProperties.GetIsInDesignMode method, I can just easily change my check in one place. With some refinements from friends at work, I condensed it to a single static property in App.xaml.cs that I can use throughout my application.
Note that the precompiler directives can be removed if you’re just targeting WPF or just targeting Silverlight
Here’s how I use it: