开发者

How does the Silverlight/WPF runtime know how to set a dependency property?

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 prop开发者_如何学Certies? I'm thinking the DP registry, considering we have to register them?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜