Enable of Disable a code from executing in Design Mode

imageNormally when you think about Application you break down your screen into controls to make things easier to maintain. In Blend and Visual Studio the Constuctor method will run always to keep you with the look and feel, However sometimes your constructor will contain parts of code that may crash and through expection because it’s looking files that doesn’t exist … etc

You need to skip that code or blend will fail in loading your screen you may replace it with other parts to maintain the look and feel.

in Earlier version of .Net Framework you can use something called Design Properties to skip that code


  1. if (!DesignerProperties.GetIsInDesignMode(this))
  2.             {
  3.               // Do Something   
  4.             }

in Metro Style Apps it’s now Part of your ApplicationModel Class in System.ComponentModel namespace

  1. using System.ComponentModel;

  1. if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
  2.             {
  3.                 //Do Something
  4.             }

Skip to main content