我相信这个活动CollectionChanged
是你所需要的。你可以这样做:
((ICollectionView)yourListCollectionView).CollectionChanged += handler;
我们这里要强制转换的原因CollectionChanged
是实现为INotifyPropertyChanged
(ICollectionView
继承自该接口)的成员,源代码在这里:
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
{
add {
CollectionChanged += value;
}
remove {
CollectionChanged -= value;
}
}
这个实现是明确的。因此,该事件对于作为公共成员的正常访问是隐藏的。要公开该成员,您可以将实例强制转换为ICollectionView
或INotifyPropertyChanged
。
. 显式实现接口时,必须先将实例显式转换为该接口,然后才能访问接口成员。
关于实现接口的示例:
public interface IA {
void Test();
}
//implicitly implement
public class A : IA {
public void Test() { ... }
}
var a = new A();
a.Test();//you can do this
//explicitly implement
public class A : IA {
void IA.Test() { ... } //note that there is no public and the interface name
// is required
}
var a = new A();
((IA)a).Test(); //this is how you do it.