ObservableCollection を ObservableCollection の派生型にコピーしようとしていますが、CollectionChanged イベントを保持したいと考えています。
これまでのところ、私は持っています:
public class PartitionCollection : ObservableCollection<AislePartition>
{
public PartitionCollection(ObservableCollection<AislePartition> other)
: base(other)
{
}
// ...
protected override void InsertItem(int index, AislePartition item)
{
// Important custom logic runs here
if (/* */)
base.InsertItem(index, item);
else
Merge(item);
}
protected void Merge(AislePartition item)
{
// ...
}
}
コレクションは正常にコピーされますが、CollectionChanged イベントも取得する必要があります。
それを行う方法はありますか?ありがとう
編集:
前:
後:
この特定のコンストラクターを使用するコード:
private static void OnSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
AisleSelection aisleSelect = args.NewValue as AisleSelection;
if (aisleSelect.Partitions == null)
aisleSelect.Partitions = new PartitionCollection();
else
aisleSelect.Partitions = new PartitionCollection(aisleSelect.Partitions);
...
}
基本的に、私がやろうとしているのは、ObservableCollection を、いくつかの主要メンバーをオーバーライドする PartitionCollection に置き換えることです。ObservableCollection はサーバーからシリアル化された形式で渡されるため、直接使用する方法はありません。