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 = OM.MajorStart(elementBounds); var elementMajorEnd = OM.MajorEnd(elementBounds); var rectMajorStart = OM.MajorStart(realizationRect); var rectMajorEnd = OM.MajorEnd(realizationRect); var elementMinorStart = OM.MinorStart(elementBounds); var elementMinorEnd = OM.MinorEnd(elementBounds); var rectMinorStart = OM.MinorStart(realizationRect); var rectMinorEnd = OM.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); }