public ObservableCollection<IndividualEntityCsidClidDetail> IncludedMembers { get; set; }
讓說我有IncludedMembers
參考我希望在收集資料的添加/刪除/編輯要發生的事件。如何獲得的ObservableCollection變化
public ObservableCollection<IndividualEntityCsidClidDetail> IncludedMembers { get; set; }
讓說我有IncludedMembers
參考我希望在收集資料的添加/刪除/編輯要發生的事件。如何獲得的ObservableCollection變化
處理CollectionChanged
事件
//註冊事件讓每一位當存在收集的變化CollectionChangedMethod
方法將被調用
yourCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler
(CollectionChangedMethod);
創建方法,這樣
private void CollectionChangedMethod(object sender, NotifyCollectionChangedEventArgs e)
{
//different kind of changes that may have occurred in collection
if(e.Action == NotifyCollectionChangedAction.Add)
{
//your code
}
if (e.Action == NotifyCollectionChangedAction.Replace)
{
//your code
}
if (e.Action == NotifyCollectionChangedAction.Remove)
{
//your code
}
if (e.Action == NotifyCollectionChangedAction.Move)
{
//your code
}
}
時間
如何處理它? – 2011-05-15 10:17:33
請參閱上面的編輯.. – 2011-05-16 18:45:21
這不會簡單地改變includeMembers – 2014-09-23 06:49:58
只需註冊收集的CollectionChanged
事件。當您添加或刪除項目或以其他方式更改集合的內容時,它將引發事件。
如果你想接收事件時,在收集的內容轉移的特性,你需要確保該項目是IObservable
第一則Subscribe()
各個對象。
您是否在WPF或WinForms環境中使用集合?你想達到什麼目的?如果你在WPF中,綁定可能比事件處理更好。 – miguel 2011-05-15 10:32:08