我创建了一个这样的依赖属性:
public partial class MyControl: UserControl
{
//...
public static DependencyProperty XyzProperty = DependencyProperty.Register("Xyz",typeof (string),typeof (MyControl),new PropertyMetadata(default(string)));
public string Xyz
{
get { return (string) GetValue(XyzProperty ); }
set { SetValue(XyzProperty , value); }
}
//...
}
然后将它绑定到我的 wpf 窗口,一切正常。
当我尝试向 setter 添加一些逻辑时,我注意到它没有被调用。我修改了get;设置到现在它们看起来像这样:
get{return null;}
set{}
它仍然有效!怎么会?GetValue/SetValue 调用有什么用?