我不知道用这种方法修复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;
}
你为什么要防止显示部分项目?只要列表是可滚动的,这对人们来说就是内容可以滚动的一个很好的指示器。 – 2011-05-18 19:45:02