DependencyProperty和Normal属性之间的主要区别 [英] Main diffrence between DependencyProperty and normal Property

查看:65
本文介绍了DependencyProperty和Normal属性之间的主要区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,Dependency属性和Normal属性之间的主要区别是exmaple或DEMO.

Anybody tell me , main difference between Dependency property and normal property  with exmaple or DEMO.

谢谢

Aniruddha acharya

Aniruddha acharya

A.Acharya对我们的反馈在Windows Store中开发和推广您的应用程序,如果有帮助,请记住将其标记为答案,如果没有帮助,则将其取消标记.

A.Acharya Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and unmark them if they provide no help.

推荐答案

简而言之,依赖属性是一种特殊的属性,它参与WPF属性系统.依赖属性提供了一种基于其他输入(例如,样式,动画,模板和 数据绑定.依赖项属性的实际值存储在DependencyObject基类的HashTable中,而不是存储在定义了依赖项属性的类的后备字段中.

In short a dependency property is a special kind of property that participates in the WPF property system. Dependency properties provide a way to compute the value of a property based on the value of other inputs such as styles, animations, templates and data binding. The actual value of a dependency property is stored in a HashTable in the DependencyObject base class rather than in a backing field of the class where the dependency property is defined.

例如,TextBlock的Foreground属性是一个依赖项属性,这意味着您可以绑定到此属性:

For example, the Foreground property of a TextBlock is a dependency property which means that you can bind to this property:

<TextBlock Text="..." Foreground="{Binding SomeSourceProperty}" />

您还可以设置其样式:

        <TextBlock Text="...">
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Setter Property="Foreground" Value="Green" />
                </Style>
            </TextBlock.Style>
        </TextBlock>

如果Foreground是普通的CLR属性,那么您将无法执行任何操作.

You wouldn't be able to do any of this if Foreground had been an ordinary CLR property.

请参阅以下链接以获取更多信息:

Please refer to the following links for more information:

依赖项属性概述: https://msdn.microsoft.com/zh-CN/library/ms752914%28v=vs.110%29.aspx
什么是依赖项属性?: http://stackoverflow.com/Questions/617312/什么是依赖属性
依赖项属性值如何存储在dependencyObject中?:

Dependency Properties Overview: https://msdn.microsoft.com/en-us/library/ms752914%28v=vs.110%29.aspx
What is a dependency property?: http://stackoverflow.com/questions/617312/what-is-a-dependency-property
how dependency property values are stored inside dependencyObject?: https://social.msdn.microsoft.com/Forums/vstudio/en-US/141db11a-e14c-4ab9-8057-edd843d31bc1/how-dependency-property-values-are-stored-inside-dependencyobject?forum=wpf


希望有帮助.


Hope that helps.

请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于DependencyProperty和Normal属性之间的主要区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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