In many ViewModels I will need a collection from another ViewModel. Basically each VIewModel has a List property which is of type ObservableCollection. and most of the time ViewA needs VIewModelA (for CRUD) and ViewModelB.List (for read-only purpose).
What is the recommended approach here?
- inject a ViewModelB into ViewModelA and expose a EntityBList property
- add/copy the same GetList procedure in ViewModelA from ViewModelB?
- in ViewA xaml reference both ViewModelA and viewModelB
I generally use option 1. Injecting a SharedViewModel singleton into view models that need the data works well. It’s also easy to add additional shared data when needed.