我如何知道依赖属性的绑定已更改?
正如这个问题中提到的,至少有两种方法可以通知绑定到依赖项属性的值已更改:
- DependencyPropertyDescriptor.AddValueChanged
- DependencyProperty.OverrideMetadata 在具有我自己的 PropertyChangedCallback 的派生类上。
这一切都工作正常,但仅当在属性上设置实际绑定时才需要通知我,而不是每次值更改时。有没有办法为此或我需要监听的事件注册回调?
我在 MSDN 中查看了类 DependencyProperty, DependencyObject、BindingOperations 和 依赖属性描述符。
As mentioned in this question, there are at least two ways by which I can be notified that the value bound to a dependency property has changed:
- DependencyPropertyDescriptor.AddValueChanged
- DependencyProperty.OverrideMetadata on a derived class with my own PropertyChangedCallback.
This is all working fine but I need to be notified only when the actual binding is set on the property not every time the value changes. Is there a way to register a callback for this or an event I need to listen to?
I have looked in MSDN on the classes DependencyProperty, DependencyObject, BindingOperations and DependencyPropertyDescriptor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为有一个“官方方法”可以做到这一点,尽管几天前我遇到了同样的问题,并想出了一个相当愚蠢但至少有效的解决方法,
对我来说效果很好,也应该对你有用:)
I don't think there is an "official way" to do that, although I had the same problem some days ago and came up with a quite stupid but at least efficient workaround
Works fine for me, should do the trick for you as well :)