Reputation: 3081
I would like to bind multiple user controls (that are of the same xaml) to different instances of a ViewModel. How should I do that?
e.g.
<myownlocation:Constructor DataContext="ViewModel" />
<myownlocation:Constructor DataContext="ViewModel" />
and during construction I have instantiated one ViewModel with the name "A" for example and the other viewModel with the name "B" and this name property is then bound in the UC.
How should I solve this?
Thanks!
Upvotes: 0
Views: 84
Reputation: 446
Assuming that both instances of the ViewModel are available as properties in the Data Context of the containing view, then you would do it like this:
<myownlocation:Constructor DataContext="{Binding ViewModelA}" />
<myownlocation:Constructor DataContext="{Binding ViewModelB}" />
Upvotes: 1