Silverlight/WPF 运行时如何知道如何设置依赖属性?
所以我认为我理解什么是依赖属性以及为什么我们需要它们 - 它们是由 Silverlight/WPF 库管理的属性,以便运行时可以对它们的设置方式进行一些控制,使它们能够执行诸如给予动画优先于属性和其他漂亮功能上的其他类型的请求之类的事情。
我的问题是,框架如何知道如何做到这一点?如果依赖属性始终通过其父对象上的 getter/setter 进行访问(遵循 GetValue()
和 SetValue()
),那么依赖存储库*如何知道< em>谁提出请求以便确定其优先级?
抱歉,如果这是一个非常基本/明显的问题。
* 管理依赖属性的容器是否有名称?我在考虑 DP 注册表,考虑到我们必须注册它们?
So I think I understand what a dependency property is and why we need them - they are properties managed by the Silverlight/WPF libraries such that the runtime can have some control over how they are set, enabling them to do such things as giving animations precedence over other types of requests on the properties and other nifty features.
My question is, how does the framework know how to do this? If dependency properties are always accessed through their getters/setters on their parent objects (which defer to GetValue()
and SetValue()
) then how can the dependency repository* know who is making the request in order to prioritize it?
Sorry if this is a very basic/obvious question.
* Is there a name for the container that manages dependency properties? I'm thinking the DP registry, considering we have to register them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有一个注册表,但它全部隐藏。不,依赖属性根本不是通过 Getter 和 Setter 设置的,而是 DependencyObject 有名为 GetValue 和 SetValue 的方法,您可以在其中实际将句柄传递给依赖属性。假设您的 DP 有注册表,并且有字典,并且 DP 的句柄(注册后获得的 DP 对象)是关键。
这样,注册表就知道何时修改、修改哪些内容、更新哪些内容以及需要向谁发送通知。
您可以使用reflector探索.NET的内部,您会发现每个DP都需要通过调用DependencyProperty.Register进行注册,然后只有您可以使用它。
Yes, there is a registry but its all hidden. And No, dependency properties are not at all set via Getter and Setter instead DependencyObject has methods called GetValue and SetValue where you actually pass handle to your dependency property. Assume your DP has registry and it has dictionary and handle to your DP (the DP object you get after registering) is key.
This way, registry knows when and what to modify and what to update and to whom it needs to send notifications.
You can use reflector to explore .NET's internal, you will get idea that every DP needs to be registered by calling DependencyProperty.Register then only you can use it.