Silverlight/WPF DependencyProperty 启用数据绑定(bind)并指示属性值何时更改,而无需实现 INotifyPropertyChanged。我的问题是这在低级别是如何工作的——DependencyProperty 或 DependencyObject 是如何工作的?当 DependencyObject、DependencyProperty 和 DispatcherObject 均未定义任何事件时执行此更改通知。这是否与 DispatcherObject.Dispatcher 有关?属性(property)?
Dependency properties, or the DependencyObject class, do not natively support INotifyPropertyChanged for purposes of producing notifications of changes in DependencyObject source property value for data binding operations.
这一出色的说明逐字逐句地摘自:
最佳答案
依赖属性在内部与绑定(bind)系统紧密集成。因此,设置依赖属性的代码可以直接调用绑定(bind)系统并告诉它进行更新,而不是“通知属性已更改”。
类似地,继承/附加属性之类的东西可以在任何后代元素上更新和/或布局/测量/排列可以更新。它甚至可以告诉任何触发器(在 Styles 或 ControlTemplates 中)被重新评估。
Dispatcher 并不是真正相关的,但可能会在此过程中使用。
简而言之,它已融入 WPF/Silverlight。
关于c# - 了解 DependencyProperty 的工作原理和实现方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7079780/