gpt4 book ai didi

wpf - 如何在根元素的所有子元素上监听 Binding.SourceUpdated?

转载 作者:行者123 更新时间:2023-12-04 00:27:01 25 4
gpt4 key购买 nike

我想在所有定义的子绑定(bind)上收听 Binding.SourceUpdated。

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

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.



这意味着我们应该能够按 DataContext 而不是按 Binding 元素监听这些事件。

最佳答案

与大多数 WPF 事件一样,SourceUpdated Routed Event .当子元素引发此事件时,也将调用放置在给定元素上的此事件的任何事件处理程序。

如果您有以下代码:

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

处理程序 OnBindingSourceUpdated将处理两个文本框的绑定(bind)源更改。将附加的事件处理程序放在最初定义数据上下文的元素上,您将收到每次源更改的通知。

关于wpf - 如何在根元素的所有子元素上监听 Binding.SourceUpdated?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7132832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com