Search code examples
silverlightseparation-of-concerns

Where should the viewModel be created?


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.


Solution

  • 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.