オブジェクトが存在するコレクションへの参照をオブジェクトに持たせたい.
私はから派生したコレクションクラスを持っていますObservableCollection<>:
public class MyObservableCollection<T> : ObservableCollection<T> where T: class, IMyItem
public interface IMyItem
{
MyObservableCollection<IMyItem> Owner;
}
Insert( )その中で、 andをオーバーライドしてRemove( )、それ自体を on のプロパティに割り当てることができるようにしましたが、そのIMyItemために許可されていません
Cannot implicitly convert type 'MyObservableCollection<T>' to
'MyObservableCollection<IMyItem>'
どうすればこの問題を回避できますか?
問題をまったく異なる方法で解決できますか、または解決する必要がありますか?
挿入からのコード:
protected override void InsertItem(int index, T item)
{
base.InsertItem(index, item);
item.Owner = this;
}