Subscribing to a Binding Class Event in Custom MarkupExtension

I am writing a MarkupExtension capable of accepting a PropertyPath. I would like to subscribe to the β€œChange” events of this PropertyPath (either DependencyProperty, or one that is updated through INotifyPropertyChanged) without ever actually calling the source property.

My code looks like this:

public override object ProvideValue(IServiceProvider serviceProvider) { var binding = new Binding(); binding.Path = Path; ... return false; } 

But I'm not sure how to continue to receive notifications from the binding object. If I contact the binding to any DependencyProperty, it will automatically call the getter property of the source, which I am trying to avoid.

It seems that I could somehow use Binding.SourceUpdatedEvent, however, since this is an attached routed event, I am not sure how to subscribe to it from MarkupExtension.

Thanks!

0
source share
2 answers

Take a look at this SO question

The idea is to create a single DP class, pass it in, and let WPF process the property path and then retrieve the value that comes out.

If this does not satisfy, you look at reflection (a lot of it).

+1
source

If Binding and DependancyProperty is the solution for you, and you are worried that you are not calling the getter, you can specify the binding mode as OneWayToSource.

 {Binding Mode=OneWayToSource} 

Or in code

 binding.Mode = BindingMode.OneWayToSource; 
0
source

All Articles