CLR属性

每一个CLR(Common Language Runtime)后面都有一个字段后台支持(Back)
C#中属性的编译结果是两个方法,只有一个拷贝

依赖注入属性Dependency Property

优点:

  • 节省实例对内存的开销
  • 属性值可以通过Binding依赖在其他对象上

    定义、注册、添加属性包装器

    条件:只能为依赖对象(继承自DependencyObject的类)添加依赖项属性
    1. public class StudentDependencyObject : DependencyObject {
    2. public int Age {
    3. get { return (int)GetValue(AgeProperty); }
    4. set { SetValue(AgeProperty, value); }
    5. }
    6. // Using a DependencyProperty as the backing store for Age. This enables animation, styling, binding, etc...
    7. public static readonly DependencyProperty AgeProperty =
    8. DependencyProperty.Register("Age", typeof(int), typeof(StudentDependencyObject));
    9. }
    1. Thickness边距类型