How to listen for Binding.SourceUpdated for all children of the root element?

I want to listen to Binding.SourceUpdated for all defined child bindings.

http://msdn.microsoft.com/en-us/library/system.windows.data.binding.sourceupdated.aspx says

Set the NotifyOnTargetUpdated or NotifyOnSourceUpdated property (or both) to true in the binding. The handler that you provide to listen to this event must be attached directly to the element in which you want to receive information about changes, or to the general data context if you want to know that something in this context has changed.

This means that we should be able to listen to this event in the DataContext instead of each Binding element.

+6
source share
1 answer

Like most WPF events, SourceUpdated is a Routed Event . Any event handler for this event placed on this element will also be called when the child element raises this event.

If you have the following code:

 <StackPanel Binding.SourceUpdated="OnBindingSourceUpdated"> <TextBlock Text="{Binding Path=A, NotifyOnSourceUpdated=True}" /> <TextBlock Text="{Binding Path=B, NotifyOnSourceUpdated=True}" /> </StackPanel> 

The OnBindingSourceUpdated handler will handle binding source changes for both text fields. Place the attached event handler in the element where the data context was originally set, and you will receive notifications for every change to the source.

+8
source

Source: https://habr.com/ru/post/895492/


All Articles