从上面我们可以看到每个属性对应一个依赖属性,根据WPF的约定依赖属性名称为:属性名+Property ,依赖属性是一个static和readonly的DependencyProperty对象,static静态表示全局可以共享数据,readonly表示只读,表示初始化之后不会改变,我们来看一下 DependencyProperty类型,我们看一下DependencyProperty内部类的成员:
自定义依赖属性
public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));
我们在这里对依赖属性有了一个简单的认识,依赖属性背后的逻辑非常复杂和强大,使我们在应用程序减少内存的使用!