Is there a way to check if WPF is currently executing in design mode or not? Is there a way to check if WPF is currently executing in design mode or not? wpf wpf

Is there a way to check if WPF is currently executing in design mode or not?


I believe you are looking for GetIsInDesignMode, which takes a DependencyObject.

Ie.

// 'this' is your UI elementDesignerProperties.GetIsInDesignMode(this);

Edit: When using Silverlight / WP7, you should use IsInDesignTool since GetIsInDesignMode can sometimes return false while in Visual Studio:

DesignerProperties.IsInDesignTool

Edit: And finally, in the interest of completeness, the equivalent in WinRT / Metro / Windows Store applications is DesignModeEnabled:

Windows.ApplicationModel.DesignMode.DesignModeEnabled


You can do something like this:

DesignerProperties.GetIsInDesignMode(new DependencyObject());


public static bool InDesignMode(){    return !(Application.Current is App);}

Works from anywhere. I use it to stop databound videos from playing in the designer.