在 ObservableCollection 中,我如何检查 CollectionChanged 事件是否为 null, 该语句抛出语法错误
if (studentList.CollectionChanged == null)
错误信息:
事件 '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; }
}
最佳答案
您无法查看事件是否具有从拥有该事件的类外部附加的处理程序。您必须为要解决的问题找到不同的解决方案。
关于c# - 我如何检查 ObservableCollection 的 "CollectionChanged"事件是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7327264/