protected void Scrollable_ShouldScrollTo(Rect shape) { if (!ShouldHandleScrollRequestsFromContent) { return; } //Rect absolute = new Rect(shape); //absolute.Location.Add(-Scrollable.DeltaX, -Scrollable.DeltaY); Rect.RectangleRelativePosition relativePosition = shape.RelativeToRectY(Scrollable.ViewPort); if (relativePosition != Rect.RectangleRelativePosition.FullyInside && relativePosition != Rect.RectangleRelativePosition.FullyContaining) { ScrollContentXY(shape.Location.X, shape.Location.Y); } }
private void MyRootControl_ShouldScrollTo(Rect shape) { const int horizBorder = 150; const int verticBorder = 50; Rect.RectangleRelativePosition RelativePosition = shape.RelativeToRectY(MainShape.Scrollable.ViewPort); int x = shape.Location.X; int y = shape.Location.Y; int totalHeight = RootBlock.MyRootControl.Bounds.Size.Y; int viewportLeft = MainShape.Scrollable.ViewPort.Location.X; int viewportRight = MainShape.Scrollable.ViewPort.Right; int viewportHeight = MainShape.Scrollable.ViewPort.Size.Y; int viewportTop = MainShape.Scrollable.ViewPort.Top; bool shouldScrollX = false; bool shouldScrollY = false; int scrollToX = 0; int scrollToY = 0; switch (RelativePosition) { case Rect.RectangleRelativePosition.FullyContaining: case Rect.RectangleRelativePosition.IntersectingBeginning: case Rect.RectangleRelativePosition.FullyBefore: case Rect.RectangleRelativePosition.IntersectingEnd: case Rect.RectangleRelativePosition.FullyAfter: shouldScrollY = true; scrollToY = y - verticBorder; break; case Rect.RectangleRelativePosition.FullyInside: default: if (totalHeight > viewportHeight && viewportHeight > 300 && totalHeight - y < 300) { shouldScrollY = true; scrollToY = totalHeight; } else if (y > viewportTop && y < viewportTop + verticBorder) { shouldScrollY = true; scrollToY = y - verticBorder; } break; } if (x < viewportLeft + horizBorder) { shouldScrollX = true; scrollToX = x - horizBorder; } if (x > viewportRight - horizBorder) { shouldScrollX = true; scrollToX = x + horizBorder; } if (shouldScrollX && shouldScrollY) { MainShape.ScrollContentXY(scrollToX, scrollToY); } else if (shouldScrollX) { MainShape.ScrollContentX(scrollToX); } else if (shouldScrollY) { MainShape.ScrollContentY(scrollToY); } }