vanja.
vanja.

Reputation: 2572

Chaining dependency properties with MVVM

I am looking for a way to expose a property in my ViewModel and have it influenced by two separate controls in my View.

In code view, I am trying to do something like this:

propdp object MyObject...

<MySelector SelectedItem="{Binding MyObject, Mode=TwoWay}" />
<MyEditor DataContext="{Binding MyObject, Mode=TwoWay}" />

The purpose of this is to let the user select an item and edit it on the same user control, but its not working for me. When a selection is made in MySelector, the change fails to propagate to MyEditor.

Is this possible to do?

Upvotes: 2

Views: 1163

Answers (2)

user7116
user7116

Reputation: 64068

If what you want to accomplish is have the Editor control point to what the Selector control is pointing to, simply adjust the MyEditor binding to the following:

<MyEditor DataContext="{Binding Path=SelectedItem, ElementName=mySelector}" />

Upvotes: 2

Jobi Joy
Jobi Joy

Reputation: 50038

<MySelector x:Name="mSelector" SelectedItem="{Binding MyObject, Mode=TwoWay}" />
<MyEditor DataContext="{Binding ElementName= mSelector,Path=mSelector}" />

Check whether that solve your problem

Upvotes: 1

Related Questions