在的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