Reputation: 3875
i have an instance of a view model and 3 other view models, each of those three view models need to access the ObservableCollection of that view model, that view model is not my main view model, should i send the instance of that view model by reference to the constructor of other view models and add it as a property?
Upvotes: 0
Views: 823
Reputation: 11783
Sounds like it shouldn't be there to begin with (if 3 other ViewModels need it to).
You could reference the ViewModel, or better yet, move that collection to your Model, or to a global resource.
Edit:
If you're not using any frameworks, you might have to jump through loops to do it, or pass references in the constructors. Have a look at these answers: similar question , another similar one .
I still believe you should just move it out of the ViewModel to a different place, since the ViewModel is basically a translator from your Model, to your View. If your collection is shared by different ViewModels, it should be in a shared location.
If you would have used Mvvm-Light, the Locator might have been useful, or another option would have been to use the messenger maybe, even though I wouldn't have done it that way...
Upvotes: 1