private int FindViewLastIndex(int firstIndex)
{
int lastIndex = firstIndex;
GeneralTransform scrollViewerTransform = this.scrollViewer.TransformToVisual(
Application.Current.RootVisual);
Rect scrollViewerRect = scrollViewerTransform.TransformBounds(
new Rect(new Point(0, 0), this.scrollViewer.RenderSize));
while (lastIndex < this.Items.Count - 1)
{
ReorderListBoxItem itemContainer = (ReorderListBoxItem)
this.ItemContainerGenerator.ContainerFromIndex(lastIndex + 1);
if (itemContainer == null)
{
break;
}
GeneralTransform itemTransform = itemContainer.TransformToVisual(
Application.Current.RootVisual);
Rect itemRect = itemTransform.TransformBounds(new Rect(new Point(0, 0), itemContainer.RenderSize));
itemRect.Intersect(scrollViewerRect);
if (itemRect == Rect.Empty)
{
break;
}
lastIndex++;
}
return lastIndex;
}