views:

101

answers:

1

Hi,

I have seen a few examples where the viewModel (in Silverlight apps) is in the UserControl.Resources XAML section of a View. I read that for using Blend, this is a good place to have it (as it gives the ability to see sample data in Blend).

However, is this the best place to have the viewModel? I read that the "view has to push services to the viewModel". What does this mean and where else could or should the ViewModel be created?

Thanks. JD.

+1  A: 

There are lots of ways that the View and the ViewModel can be connected. The simplest approach is using the Resources like you mention or even easy just setting the DataContext of the View in the Xaml to an instance of the ViewModel.

From there things get more complex and really it depends on the framework you use:

So the approach you take will depend on what style you like. There are many ways to do this and right now there are a lot of MVVM frameworks showing up.

Bryant
Thanks Bryant. I am dabbling with Prism at the moment and was not even aware of the others (although I had heard of commands with Caliburn). Where should I look or can you tell me how I would do it with prism? So far I have seen a view registered in the unity container.
JD
You can take any of the approaches above with Prism as well. I don't think Prism is prescriptive about how to hook them together. See http://development-guides.silverbaylabs.org/Video/Silverlight-Prism for a quick 101 on MVVM with Prism.
Bryant