我不知道用這種方法修復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