3

Assume the following data-flow happens using Binding:

PropertyA <--> DependencyProperty <--> PropertyB
  • The <--> marks represents a TwoWay binding mode.
  • Both PropertyA and PropertyB classes implement INotifyPropertyChanged and invoke OnPropertyChanged method in their setter accessor when changed.

The binding compiler setting starts from the above flow left side to the right, that means the last binding set is between DependencyProperty and PropertyB.

The problem is when PropertyA notifies for property changed, DependencyProperty doesn't invoke her OnPropertyChangedCallback method.

On the contrary, when PropertyB notifies for property changed, DependencyProperty DOES invoke her OnPropertyChangedCallback method.

I would like to know if it even possible to achieve such behavior using the .NET Binding mechanism, or there is another way.

Thanks in advance.

UPDATE

The term "chain" in the question context, for example, means:

when PropertyA notifies for a change, PropertyB will be notified from DependencyProperty which notified from PropertyA change, and vice versa.

The above example "chains" between PropertyA to PropertyB using DependencyProperty.

4
  • Reading your title : do you want to achieve some kind of concatenation ? Commented Nov 12, 2015 at 19:26
  • Emmanuel DURIN thank you for your answer, yes I do ("...or there is another way."). Commented Nov 12, 2015 at 20:24
  • That's really not visible in your question - or I missed something - Do you want to concatenate PropA and PropB ? - Are they strings ? Or do you want any change happeing to A or B change the dep. prop( that would have strange side effects) ? Commented Nov 12, 2015 at 21:08
  • Emmanuel DURIN I updated the question for clarity. Commented Nov 13, 2015 at 9:13

1 Answer 1

2

You can't have two bindings on the same DependencyProperty being the target.

It would mean that you 'd have two sources for the same DependencyProperty.

But you can have a property (on the Model or ViewModel) being the source for many dependency properties. That's pretty common.

It seems normal to me if you ve got the OnPropertyChangedCallback called only when one property is changed.

There can be only one source, and the last binding wins.

Here is a nicepage with schemas : http://blog.scottlogic.com/2012/04/05/everything-you-wanted-to-know-about-databinding-in-wpf-silverlight-and-wp7-part-one.html

EDIT

If you want to have two properties of two objects in phase, you can use ViewModel as an intermediary between A holding PropB and B holding PropB.

So you'd have : | <--> ClassA.PropA View <---> ViewModel.Prop-| | <--> ClassB.PropB

It means : - ViewModel Object would register to the PropertyEventChanged of ClassA and ClassB.
ViewModel would raise an event if ClassA or ClassB would raise an event for PropA or PropB change.

  • ViewModel would call ClassA.PropA.set and ClassB.PropB.set when ViewModel Prop.set would be called.

  • When get of ViewModel, only ClassA.PropA would be read. But it wouldn't matter because PropA and PropB are worth the same.

Hope it helps, regards

Regards

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer, please assign an link with your answer so I know it is based upon either the language specification or some reliable source.
Two-way or not doesn't even matter. A single dependency property can't be the target of two Bindings at the same time. The question doesn't make sense.
@Eido, I found no wording there is only one source for dep.prop. The closest reliable source is Clemens (46K reputation). But it can't work with two source for a dep.property. It would mean the dep.prop could be valued by two properties with two different values at the same time
@Eido. I made an edit. Maybe I understood what could help you. Please have a look when you have time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.