依赖属性 dependency property WPF,为什么要用DDP?
2013-08-11 20:20
459 查看
使用依赖属性的原因:link http://stackoverflow.com/questions/1723756/why-dependency-properties
This helped me understand the reasoning:
The main difference is, that the value of a normal .NET property is read directly from a private
member in your class, whereas the value of a
DependencyProperty is resolved dynamically when calling theGetValue()
method that is inherited from DependencyObject.
DPP是动态读取进来的,而不是像原始Property那样,实际是存储在一个private的成员里。
When you set a value of a dependency property it is not stored in a field of your object, but in
adictionary of keys and values provided by the base class DependencyObject. The key of an
entry is the name of the property and the value is the value you want to set.
DDP这货是存在DependencyObject这个基类里的。
The advantages of dependency properties are as follows:
好处如下
Reduced memory footprint(减少存储,只存改变的)
It's a huge dissipation to store a field for each property when you think that over 90% of the properties of a UI control typically stay at its initial values. Dependency properties solve these problems
by only store modified properties in the instance. The default values are stored once within the dependency property.
Value inheritance(值继承)
When you access a dependency property the value is resolved by using a value resolution strategy.
If no local value is set, the dependency property navigates up the logical tree until it finds a value. When you set the FontSize on the root element it applies to all textblocks
below except you override the value.
Change notification(改变时候有提醒事件,Notification)
Dependency properties have a built-in change notification mechanism.
By registering a callback in the property metadata you get notified, when the value of the property has been changed. This is also used by the databinding.
From: WPF Tutorials.
This helped me understand the reasoning:
The main difference is, that the value of a normal .NET property is read directly from a private
member in your class, whereas the value of a
DependencyProperty is resolved dynamically when calling theGetValue()
method that is inherited from DependencyObject.
DPP是动态读取进来的,而不是像原始Property那样,实际是存储在一个private的成员里。
When you set a value of a dependency property it is not stored in a field of your object, but in
adictionary of keys and values provided by the base class DependencyObject. The key of an
entry is the name of the property and the value is the value you want to set.
DDP这货是存在DependencyObject这个基类里的。
The advantages of dependency properties are as follows:
好处如下
Reduced memory footprint(减少存储,只存改变的)
It's a huge dissipation to store a field for each property when you think that over 90% of the properties of a UI control typically stay at its initial values. Dependency properties solve these problems
by only store modified properties in the instance. The default values are stored once within the dependency property.
Value inheritance(值继承)
When you access a dependency property the value is resolved by using a value resolution strategy.
If no local value is set, the dependency property navigates up the logical tree until it finds a value. When you set the FontSize on the root element it applies to all textblocks
below except you override the value.
Change notification(改变时候有提醒事件,Notification)
Dependency properties have a built-in change notification mechanism.
By registering a callback in the property metadata you get notified, when the value of the property has been changed. This is also used by the databinding.
From: WPF Tutorials.
相关文章推荐
- WPF中的依赖属性(Dependency Property)
- 一站式WPF--依赖属性(DependencyProperty)
- 一站式WPF--依赖属性(DependencyProperty)二
- 一站式WPF--依赖属性(DependencyProperty)
- WPF 依赖属性,用户控件依赖属性(DependencyProperty 依赖属性、GetValue() SetValue() CLR属性包装器、SetBinding 数据绑定)
- WPF学习笔记8: 依赖属性(Dependency Property)
- Silverlight&WPF依赖属性DependencyProperty讲解
- 一站式WPF--依赖属性(DependencyProperty)二
- WPF 使用依赖属性(DependencyProperty) 定义用户控件中的Image Source属性
- 转载:一站式WPF--依赖属性(DependencyProperty)
- 一站式WPF--依赖属性(DependencyProperty)二
- #123 – Coercing a Dependency Property(强制转换依赖属性的值)
- Silverlight:Dependency Property(依赖属性)
- javascript中依赖属性(Dependency Property)的实现
- 依赖属性(DependencyProperty)
- #118 – Don’t Add Code to Dependency Property Getter/Setter(不要在依赖属性的Getter/Setter中加入处理代码)
- Silverlight:Dependency Property(依赖属性)学习笔记
- #117 – Registering a Dependency Property(注册一个依赖属性)
- WF,WPF,Silverlight的DependencyProperty 附加属性
- #154 – Reusing an Existing Dependency Property in Your Class(重用依赖属性)