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.
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.
Just to add to these suggestions, you probably want to optimize for production deployment.
If you need to check the design mode in the ViewModel, you should only do so when in DEBUG
mode, otherwise the released version will always have to perform unnecessary checks.
When developing, if in design mode you can exit the method (or even stub out some fake data).
Put this code as the first line of your constructor (or whatever code is being called):
C#:
<!-- language: lang-cs -->#if DEBUG
if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) return;
#endif
VB:
<!-- language: lang-vb -->#If DEBUG Then
If DesignerProperties.GetIsInDesignMode(New DependencyObject()) Then Return
#End If