为什么WPF依赖属性必须是静态 [英] Why dependency properties in WPF has to be Static

查看:413
本文介绍了为什么WPF依赖属性必须是静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么一个依赖属性必须是静态的?

Why a dependency property has to be Static?

我已经看到,它已被要求在这里的一些帖子,但我不能够正确理解。

I have seen that it has been already asked in some post here, but I am not able to understand it properly.

这将是巨大的,如果有人可以帮我一个小片段明白了。

It will be great if someone can help me understand with a small snippet too.

推荐答案

在这里神奇的是,声明的DependencyProperty 静态不是它的(即存储器)。您使用静态关键字添加的声明是的DependencyProperty DependencyObject的只是标识符,因为同样的标识将由DependencyObject的所有实例共享,因此确定该属性是有意义的,使其静态

The magic here is, the declaration of DependencyProperty is static not its value (i.e the memory storage). The declaration that you add with static keyword is just the identifier of the DependencyProperty for the DependencyObject because the same identifier will be shared by all the instances of that DependencyObject to identify the property hence it makes sense to make it static.

在另一方面,当你调用设置 DependancyProperty 的值的SetValue DependancyObject 实例,那么 DependancyObject 在其上调用setValue将存储其本地值的财产。这是由内部处理的 DependancyObject 类,维持类的词典里面有 DependancyProperty 标识符和本地值。

On the other hand, when you set the value of DependancyProperty by calling the SetValue on DependancyObject instance, then each instance of DependancyObject on which the setvalue is called will store its local value of the Property. This is handled internally by the DependancyObject class which maintain sort of Dictionary which has the mapping between the DependancyProperty identifier and the local value.

这篇关于为什么WPF依赖属性必须是静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆