在的ObservableCollection我怎么能检查CollectionChanged事件为空或不是, 这个语句抛出语法错误如何检查的ObservableCollection的“CollectionChanged”事件为空或不是
if (studentList.CollectionChanged == null)
的ErrorMessage:
事件'System.Collections.ObjectModel.ObservableCollection.CollectionChanged'只能出现在+ =的左侧或 - =
示例代码:
public class School
{
public School()
{
studentList = new ObservableCollection<Student>();
//only when studentList.CollectionChanged is empty i want
// to execute the below statement
studentList.CollectionChanged += Collection_CollectionChanged;
}
public ObservableCollection<Student> studentList { get; set; }
}
我不知道,你可以。为什么你想要,但是? – wilbur4321
好问题,在上面的代码中它只会被执行一次。但在我实际的情况下,当序列化和反序列化我松散collectionchanged事件,所以我实现我自己的ondeserialized方法,并附上resechanged编程。我需要检查。 – user841683