防止WPF ListView或ListBox显示"half"项

Tal*_*ode 5 wpf listview listbox

在我们的应用程序中,我们在网格中有一些ListViews和ListBoxes,您可以借助网格分割器更改控件的实际高度.这样做时,您可以排列ListBox的高度,因此其中一个项目不完全可见,因为ListView变短以显示它.

这是我们不想要的行为.

从我的研究到目前为止似乎没有办法阻止ListBox或ListView显示部分项目,但也许有人找到另一种方法来处理这个问题.当它只有一半可见时,该物品可能会触发它自己不可见.但是我们怎么能找到?

我们欢迎任何建议.

Ed *_*tes 1

我不知道如何以这种方式修复 ListView 。不过,对于 ListBox,您可以重写 ArrangeOverride 并自行排列项目。堆叠您想要看到的项目,并排列您不希望可见的项目(例如,部分可见的项目),以便它们不可见。例如,非虚拟化版本:

    /// <summary>
    /// Used to arrange all of the child items for the layout.
    /// Determines position for each child.
    /// </summary>
    /// <param name="finalSize">Parent passes this size in</param>
    /// <returns>Parent size (always uses all of the allowed area)</returns>
    protected override Size ArrangeOverride(Size finalSize)
    {
        // Arrange in a stack
        double curX = 0;
        double curY = 0;
        foreach (UIElement child in InternalChildren)
        {
            double nextY = curY + child.DesiredSize.Height;
            if (nextY > finalSize.Height)         // Don't display partial items
                child.Arrange(new Rect());
            else
                child.Arrange(new Rect(curX, curY, child.DesiredSize.Width, child.DesiredSize.Height);
            curY = nextY;
        }

        return finalSize;
    }
Run Code Online (Sandbox Code Playgroud)