CLR属性
每一个CLR(Common Language Runtime)后面都有一个字段后台支持(Back)
C#中属性的编译结果是两个方法,只有一个拷贝
依赖注入属性Dependency Property
优点:
- 节省实例对内存的开销
- 属性值可以通过Binding依赖在其他对象上
定义、注册、添加属性包装器
条件:只能为依赖对象(继承自DependencyObject的类)添加依赖项属性public class StudentDependencyObject : DependencyObject {
public int Age {
get { return (int)GetValue(AgeProperty); }
set { SetValue(AgeProperty, value); }
}
// Using a DependencyProperty as the backing store for Age. This enables animation, styling, binding, etc...
public static readonly DependencyProperty AgeProperty =
DependencyProperty.Register("Age", typeof(int), typeof(StudentDependencyObject));
}
Thickness边距类型