0
我有一系列嵌套集合,我需要檢測從最高層到最低層的任何位置的更改。首先,我將顯示我的代碼:如何獲取嵌套集合更改事件以冒泡
public class CategoricalDataItem
{
public string XValue { get; set; }
public double YValue { get; set; }
public SolidColorBrush Color { get; set; }
public CategoricalDataItemCollection SimpleSubData { get; set; }
}
[Serializable]
public class CategoricalDataItemCollection : ObservableCollection<CategoricalDataItem>
{
public string Descriptor { get; set; }
}
此代碼針對下鑽圖表進行構建。基本上,我允許5層深。開發人員可以創建CategoricalDataItemCollection的實例,併爲該集合中的每個CategoricalDataItem創建一個CategoricalDataItemCollection的新實例,依此類推。我需要知道是否有任何項目被添加或從任何這些嵌套集合中刪除。 CollectionChanged事件僅檢測第一層中的更改。建議將不勝感激。
我對事件很糟糕,所以請原諒我的無知。最上層實際上是CategoricalDataItemCollection而不是CategoricalDataItem。那麼,我是否需要在CategoricalDataItemCollection類中重複這種方法,以便我可以在我的調用類中訂閱該事件? – flyNflip
@flyNflip我已經更新了我的回答,讓集合進行監控。祝你好運! – TyCobb
非常感謝。我現在就試試看。 – flyNflip