How do I stop my ViewModel code from running in the designer?

Brian Ortiz picture Brian Ortiz · Sep 21, 2010 · Viewed 11.4k times · Source

I'm developing a networked WPF application with the MVVM pattern and it seems that it's running and connecting to servers in the designer.

I know about the IsInDesignMode property, but I'm not sure how to access it in a ViewModel.

Answer

neolei picture neolei · Sep 21, 2010
DependencyObject dep = new DependencyObject();
if (DesignerProperties.GetIsInDesignMode(dep))
{
    ...
}