我有一个bool类型的依赖项属性
public static readonly DependencyProperty SControlParamsProperty =
DependencyProperty.Register(
"SControlParams",
typeof(bool),
typeof(PView),
new PropertyMetadata(OnShowHideSControlChanged)
);
和财产:
public bool SControlParams
{
get { return (bool)GetValue(SControlParamsProperty); }
set
{
SetValue(SControlParamsProperty, value);
}
}
和绑定
var binding = new Binding("SControlParams");
this.SetBinding(SControlParamsProperty, binding);
和VM中的属性:
bool _sControlParams = false;
public bool SControlParams
{
get { return _sControlParams; }
set
{
_sControlParams = value;
OnPropertyChanged("SControlParams");
}
}
它很棒!
但是当我在VM中更改属性时,绑定工作并在视图中调用OnShowHideSControlChanged。
但是, 当我只将属性的类型更改为MyType时:
public static readonly DependencyProperty SControlParamsProperty =
DependencyProperty.Register(
"SControlParams",
typeof(MyType ),
typeof(PView),
new PropertyMetadata(OnShowHideSControlChanged)
);
public MyType SControlParams
{
get { return (MyType)GetValue(SControlParamsProperty); }
set
{
SetValue(SControlParamsProperty, value);
}
}
并在VM中:
MyType _sControlParams = ...;
public MyType SControlParams
{
get { return _sControlParams; }
set
{
_sControlParams = value;
OnPropertyChanged("SControlParams");
}
}
处理程序OnShowHideSControlChanged不再调用..
可能有什么问题? 感谢