我正在尝试使用WPF ListBox创建Graph控件.我创建了自己的Canvas,它来自VirtualizingPanel,我自己处理项目的实现和虚拟化.
然后将列表框的项面板设置为我的自定义虚拟化画布.
我遇到的问题发生在以下场景中:
是什么导致了这个"DisconnectedItem"的创建?如果我首先虚拟化B,然后是A,则不会创建此项目.我的理论是,虚拟化ListBox中其他项之前的项会导致子项断开连接.
使用包含数百个节点的图表时问题更加明显,因为当我平移时,我最终会收到数百个断开连接的项目.
以下是画布代码的一部分:
/// <summary>
/// Arranges and virtualizes child element positionned explicitly.
/// </summary>
public class VirtualizingCanvas : VirtualizingPanel
{
(...)
protected override Size MeasureOverride(Size constraint)
{
ItemsControl itemsOwner = ItemsControl.GetItemsOwner(this);
// For some reason you have to "touch" the children collection in
// order for the ItemContainerGenerator to initialize properly.
var necessaryChidrenTouch = Children;
IItemContainerGenerator generator = ItemContainerGenerator;
IDisposable generationAction = null;
int index = 0;
Rect visibilityRect …Run Code Online (Sandbox Code Playgroud)