private bool ShouldContinueFillingUpSpace( int index, GenerateDirection direction) { bool shouldContinue; if (!IsVirtualizingContext) { shouldContinue = true; } else { var realizationRect = m_context.RealizationRect; var elementBounds = m_elementManager.GetLayoutBoundsForDataIndex(index); var elementMajorStart = OrientationBasedMeasures.MajorStart(elementBounds); var elementMajorEnd = OrientationBasedMeasures.MajorEnd(elementBounds); var rectMajorStart = OrientationBasedMeasures.MajorStart(realizationRect); var rectMajorEnd = OrientationBasedMeasures.MajorEnd(realizationRect); var elementMinorStart = OrientationBasedMeasures.MinorStart(elementBounds); var elementMinorEnd = OrientationBasedMeasures.MinorEnd(elementBounds); var rectMinorStart = OrientationBasedMeasures.MinorStart(realizationRect); var rectMinorEnd = OrientationBasedMeasures.MinorEnd(realizationRect); // Ensure that both minor and major directions are taken into consideration so that if the scrolling direction // is the same as the flow direction we still stop at the end of the viewport rectangle. shouldContinue = (direction == GenerateDirection.Forward && elementMajorStart < rectMajorEnd && elementMinorStart < rectMinorEnd) || (direction == GenerateDirection.Backward && elementMajorEnd > rectMajorStart && elementMinorEnd > rectMinorStart); } return(shouldContinue); }