Reputation: 401
I have build a WCF template service which talks (original: discuss) with my EF connected to my database. Then I have my main aplication which a simple WPF implementing MVVM light. My main application is referecing my WCF service and has created the config file automatically.
In my ViewModel constructor I am calling my WCF service in order to get the collecton of data which will be bound to the view.
Toruble is that doing that, the Datacontext which is initialised to the ViewModelLocator.MainStatic is generating an error "Cannot create instance of "ViewModelLocator".
If I remove the service call from the viewmodel, error desapperas but could not get data of course.
Any idea how to implement service call in order to populate collection in a MVVM light tool kit ? Any sample you have to go throuh ?
Unfortunatly there is no such exemple around. and could get it
Thanks for you help serge
Upvotes: 1
Views: 562
Reputation: 16926
In general I would assume that it is because you making the call at design time. Use the IsInDesignModeStatic
in your view model to distinguish run time code and design time code. In the designtime code I would add some data manually to make it easier for yo to design your view..
See also this discussion for further guidance.
And this post the point that calls to Databases don't work either in design mode.
Edit
Laurent also is bloging about this topic.
Upvotes: 3
Reputation: 3623
you could try the following.
MainViewModel()
{
if(!IsInDesignMode)
{
//pull data from service
}
}
Upvotes: 2