Reputation: 9242
1 -> At most of the places i found MVVM articles that use Views so are these Views corresponds to Xaml Pages or Controls in Xaml Page. Like they say each view should have separate Viewmodel does it mean that each of my xaml page is a view and it should have Viewmodel.
2- > I have used more that three grids on the same page and handling their visibility using Databinding from a Sample Viewmodel and these Grids data has been handled from the sample Viewmodel and hence my viewmodel code becoming large and larger.So i got confused are these grid corresponds to Views and do i have to make different viewmodels for these grids. Hope you guys get it. I working on windows 8 metro style apps.
Upvotes: 0
Views: 103
Reputation: 69959
Yes, in general, each view should have its own view model. However, that is really up to the developer or development team. For example, a main view might have child views (often for the convenience of not duplicating sections of code). It is entirely possible to use one main view model for the main view and the child views together, or separate view models, one for each view.
If you really don't want large view models, then you could go for the second option, although this could add an additional layer of complexity when it comes to communicating between parent and child view models. If your view models don't need to communicate and you don't mind large view models, then you could go for option one.
It really depends on your personal coding preferences. It is worth noting that not every data object has to have it's own view model, although some developers like to wrap their business objects in view models. In this case, it is less likely that every view model would have its own view, unless you count a rendered DataTemplate
as a view (which most people don't).
Why not just try out different options and see what suits you?
Upvotes: 1