开发者

How to listen Binding.SourceUpdated on all children of a root element?

开发者 https://www.devze.com 2023-03-30 01:09 出处:网络
I want to listen Binding.SourceUpdated on all the child bindings defined. http://msdn.microsoft.com/en-us/library/system.windows.data.binding.sourceupdated.aspx says

I want to listen Binding.SourceUpdated on all the child bindings defined.

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 you provide to listen for this event must be attached directly to the element where you want to be informed of changes, or to the overall data context if you want to be aware that anything in the context has changed.

That means we should be able to l开发者_开发知识库isten those event per DataContext instead of per Binding element.


Like most WPF events, SourceUpdated is a Routed Event. Any event handler for this event placed on a given element will also be called when a 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 handler OnBindingSourceUpdated will handle binding source changes for both textboxes. Place the attached event handler on the element where the data context is originally defined and you'll get notifications for every source change.

0

精彩评论

暂无评论...
验证码 换一张
取 消