Snowflake
Snowflake

Reputation: 3081

Binding user control to instances of a datacontext?

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

Answers (1)

XVar
XVar

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

Related Questions