wpf.net-3.5

Is there a DesignMode property in WPF?


In Winforms you can say

if ( DesignMode )
{
  // Do something that only happens on Design mode
}

is there something like this in WPF?


Solution

  • Indeed there is:

    System.ComponentModel.DesignerProperties.GetIsInDesignMode

    Example:

    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Controls;
    
    public class MyUserControl : UserControl
    {
        public MyUserControl()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                // Design-mode specific functionality
            }
        }
    }