什么是依赖属性以及为什么我们在wpf中使用它以及为什么它总是静态只读

问题描述:

任何人都可以告诉我有关依赖属性的事情。

提前谢谢

Can anyone tell me clearly about dependency property.
Thanks in advance

好吧,你吞下了纯粹的术语诱饵,如果您认为依赖属性始终是静态只读。差远了。 Always static不是属性(当然可以是静态的),但类 StaticProperty 的实例,这是 - 惊喜! - 不是财产。 (因此,只读属性只是你的幻想。)



这是一个实现属性所需的静态字段,一种属性描述符,它是一个真正的.NET属性,当然,不必是静态的。



您可以阅读原始文档并理解所有内容:https://msdn.microsoft.com/en-us/library/ms752914%28v=vs .110%29.aspx



当然,它需要使用你大脑的肌肉。如果您认为这很困难,我可以为您提供非常简化,极简短的解释,包括使用此功能的想法和技术,解释基本原理,以及尽可能短的代码示例。请参阅我的文章的这一部分: 不需要的WPF ProgressBar动画问题:更清晰的解决方案(3.3。依赖属性的美德)



文章本身非常微不足道,专注于一个小问题,但依赖属性功能的插图是非常清晰和简约的。当然,我的解释并不全面。有关所有细节,请参阅第一个链接。



-SA
All right, you swallowed the pure terminological bait, if you think that dependency property "is always static readonly". Not even close. "Always static" is not a property (which is of course can be static), but the instance of the class StaticProperty, which is — surprise! — is not a property. (Therefore, "readonly property" is just your fantasy.)

This is a static field needed to implement the property, a kind of a property descriptor, which is a real .NET property and, of course, does not have to be static.

You can read original documentation and understand it all: https://msdn.microsoft.com/en-us/library/ms752914%28v=vs.110%29.aspx.

Of course, it requires using your brain's muscles. If you think it's difficult, I can offer you very simplified, extremely short explanation of the idea and the technique of using of this feature, with explanation of the rationale, complete with a shortest possible code sample. Please see just this section of my article: The Problem of Unwanted WPF ProgressBar Animation: a Clearer Solution (3.3. By Virtue of Dependency Property).

The article itself is very insignificant, dedicated to a tiny problem, but the illustration of the dependency property feature is really clear and minimalistic. Of course, my explanation is not comprehensive. For all the detail, please see the first link.

—SA