您也可以使用ICollectionView
具有一些扩展功能的过滤器。如果您想要预制课程,请查看Code Project 中提供的课程。
特别是,我注意到 UI 订阅了该VectorChanged
事件,因此您应该只执行IObservableCollection
评论中前面提到的实现。
该VectorChanged
事件采用 type 的接口IVectorChangedEventArgs
,我环顾四周时没有发现具体的类。不过创建一个并不难。这是一个可以类似于创建NotifyPropertyChangedEventArgs
. 它是私有的,因为它只在集合类中使用。
private sealed class VectorChangedEventArgs : IVectorChangedEventArgs
{
public VectorChangedEventArgs(NotifyCollectionChangedAction action, object item, int index)
{
switch (action)
{
case NotifyCollectionChangedAction.Add:
CollectionChange = CollectionChange.ItemInserted;
break;
case NotifyCollectionChangedAction.Remove:
CollectionChange = CollectionChange.ItemRemoved;
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Replace:
CollectionChange = CollectionChange.ItemChanged;
break;
case NotifyCollectionChangedAction.Reset:
CollectionChange = CollectionChange.Reset;
break;
default:
throw new ArgumentOutOfRangeException("action");
}
Index = (uint)index;
Item = item;
}
/// <summary>
/// Gets the affected item.
/// </summary>
public object Item { get; private set; }
/// <summary>
/// Gets the type of change that occurred in the vector.
/// </summary>
public CollectionChange CollectionChange { get; private set; }
/// <summary>
/// Gets the position where the change occurred in the vector.
/// </summary>
public uint Index { get; private set; }
}