Multiple ViewModels associated with a single view

Viewed 25194

I have a View that displays a DataGrid which is bound to an ObservableCollection in the ViewModel. For the sake of discussion, let's say we have a Team View containing a Team DataGrid, in which each row represents a Player.

My question is about what data type I should use to represent the players in my Team collection. Is it a good idea for the items in the collection to be ViewModels themselves? In this case, my Team View would be associated with a single Team ViewModel as well as any number of Player ViewModels (in the Team collection).

Does having multiple ViewModels associated with a single View violate any design guidelines for MVVM , and is there a preferred way of implementing this scenario?

Thanks!

4 Answers

By CLEAN COD SOLID principles, it is nice to associate one view model to one view. Separation of concerns should be separated for each view and it's much easier to maintain the codebase in the future. You can do it but it's not recommended.

Related