Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf NotifyCollectionChangedAction.重置和虚拟化StackPanel容器重建_Wpf_Wpf Controls - Fatal编程技术网

Wpf NotifyCollectionChangedAction.重置和虚拟化StackPanel容器重建

Wpf NotifyCollectionChangedAction.重置和虚拟化StackPanel容器重建,wpf,wpf-controls,Wpf,Wpf Controls,我有ICollectionView的自定义实现,在添加许多项时使用NotifyCollectionChangedAction.Reset事件(因为它比为每个元素调用NotifyCollectionChangedAction.add要快)这样做的缺点是,当引发NotifyCollectionChangedAction.Reset时,VirtualizationStack面板正在重新初始化其项目容器。这是virtualizationstackpanel基类Panel.cs // This metho

我有ICollectionView的自定义实现,在添加许多项时使用NotifyCollectionChangedAction.Reset事件(因为它比为每个元素调用NotifyCollectionChangedAction.add要快)这样做的缺点是,当引发NotifyCollectionChangedAction.Reset时,VirtualizationStack面板正在重新初始化其项目容器。这是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事件并避免重建项目容器的这种副作用?

创建一个自定义面板,覆盖OnItemChanged方法并实现您自己的逻辑?OnItemChanged是私有方法。不,它是受保护的和虚拟的,这意味着它可以在派生类中被覆盖。