NotifyCollectionChangedAction.Reset和VirtualizationStackPanel容器重建

时间:2018-06-23 08:57:20

标签: wpf wpf-controls

我具有ICollectionView的自定义实现,并且在添加许多项时使用NotifyCollectionChangedAction.Reset事件(因为它比为每个元素调用NotifyCollectionChangedAction.Add更快)的缺点是VirtualizationStack面板正在重新初始化其项引发NotifyCollectionChangedAction.Reset时的容器。这是virtualizationstackpanel基类Panel.cs。

// This method returns a bool to indicate if or not the panel layout is affected by this collection change
    internal virtual bool OnItemsChangedInternal(object sender, ItemsChangedEventArgs args)
    {
        switch (args.Action)
        {
            case NotifyCollectionChangedAction.Add:
                AddChildren(args.Position, args.ItemCount);
                break;
            case NotifyCollectionChangedAction.Remove:
                RemoveChildren(args.Position, args.ItemUICount);
                break;
            case NotifyCollectionChangedAction.Replace:
                ReplaceChildren(args.Position, args.ItemCount, args.ItemUICount);
                break;
            case NotifyCollectionChangedAction.Move:
                MoveChildren(args.OldPosition, args.Position, args.ItemUICount);
                break;

            case NotifyCollectionChangedAction.Reset:
                ResetChildren();
                break;
        }

        return true;
    }

这会影响性能,因为新创建的项目容器的布局已更新,并且会导致明显的延迟。我的问题是有一种使用方法 NotifyCollectionChangedAction.Reset事件并避免重建项目容器的这种副作用?

0 个答案:

没有答案