Reputation: 2181
I have a DomainView that allows you to select an Entity in my domain. The Entity is displayed in an EntityView within the DomainView.
My question is what should the 'DomainViewModel' property be that the EntityView binds to?
All would work, I just wondered what would be the 'MVVM-way'? My preference would be for one of the last two.
Lee
Upvotes: 0
Views: 288
Reputation: 358
With the typical 'MVVM-way', ViewModels shouldn't be aware of other ViewModels and the relationship between View and ViewModel is 1-1.
Sounds like your real question is "How do I communicate data between ViewModels"? A common Master/Details interaction.
Are you using any frameworks? I am personally more familiar with PRISM, but the concepts are similar in MVVM Light and others. In PRISM, a good solution is the EventAggregator
. The DomainViewModel publishes an "EntitySelected" aggregate event that is subscribed to by the EntityViewModel.
Another option is to inject a common service (or model, depending on your style) into both ViewModels. That service would provide a public property like CurrentEntity that is set by the DomainViewModel as needed.
Either would provide a mechanism of communicating data between the ViewModels without those ViewModels having any dependency on each other.
Upvotes: 1