我有一个奇怪的现象:的PropertyChanged没有发射
在.NET CF项目还有一类(称为A),它具有以下结构:
public partial class A: Form, INotifyPropertyChanged
{
//for simplicity stripping off everything unrelated to this problem
private int _SelectedRowsCount = 0;
public int SelectedRowsCount
{
get { return _SelectedRowsCount; }
set
{
_SelectedRowsCount = value;
OnPropertyChanged("SelectedRowsCount");
}
}
public bool enableCollectionButton
{
get { return SelectedRowsCount > 0; }
}
//....
//
//
void SomeMethod()
{
//for simplicity:
SelectedRowsCount = 1; //<- HERE NOT FIRING Propertychanged for enableCollectionButton
}
}
类正确地实现了INotifyPropertyChanged的接口,使SelectedRowsCount属性触发属性更改通知(我使用调试器对此进行了评估)。 的enableCollectionButton属性数据绑定到一定的控制,像这样:
someButton.DataBindings.Add("Enabled", this, "enableCollectionButton");
但enableCollectionButton属性不会更改(尽管这取决于SelectedRowsCount的值)。此属性应该在SelectedRowsCount属性的更改上进行评估,但不是!
为什么这不起作用,我怎么想?
在此先感谢
非常感谢!我怎么能负责吗?!我应该去散步!!哈哈!是的,你是关于命名约定(通常我遵守约定)!非常感谢 – 2010-10-24 08:59:22
不客气! – 2010-10-24 09:13:32