tags:

views:

11

answers:

1

Hello

I put some data access logic in my default construct of ViewModel class. However, whenever try to open xaml designer window, visualstudio try to execute default constructor of ViewModel, then popup error window from this.

How can I prevent execution of default constructor in ViewModel class. I know GetIsInDesignModel() method can do this in codebehind class, but it is impossible to use in ViewModel class because parameter of this method require DependencyObject type.

any solution for this?

+1  A: 

You can access the IsInDesignMode property statically in your ViewModel code with

(bool)DependencyPropertyDescriptor.FromProperty(
                                 DesignerProperties.IsInDesignModeProperty,
                                 typeof(DependencyObject)
                                 ).Metadata.DefaultValue;
John Bowen
Thanks John, That is exactly what I wanted
kwon