Beispiel #1
0
        /// <summary>
        /// Reset the scrolling state to a valid location, i.e. ensure that the offset is not upper than the ContentSize.
        /// </summary>
        /// <param name="scrollView"></param>
        /// <param name="animationMode">Specifies animation mode to use to animate the scrolling (or not).</param>
        public static void ClearCustomScrollOffset(this UIScrollView scrollView, ScrollingMode animationMode = ScrollingMode.Forced)
        {
            var viewPort = scrollView.Bounds;
            var x        = scrollView.ContentOffset.X;
            var y        = scrollView.ContentOffset.Y;

            var maxX = scrollView.ContentSize.Width - viewPort.Width;
            var maxY = scrollView.ContentSize.Height - viewPort.Height;

            x = (nfloat)Math.Max(0, (nfloat)Math.Min(maxX, x));
            y = (nfloat)Math.Max(0, (nfloat)Math.Min(maxY, y));

            switch (animationMode)
            {
            case ScrollingMode.NotAnimated:
                scrollView.SetContentOffset(new CGPoint(x, y), false);
                break;

            case ScrollingMode.Animated:
                scrollView.SetContentOffset(new CGPoint(x, y), true);
                break;

            case ScrollingMode.Forced:
                scrollView.ContentOffset = new CGPoint(x, y);
                break;

            default:
                throw new NotSupportedException("Unknown animation mode");
            }
        }
 /// <summary>
 /// Sets the ScrollingMode for the drop action.
 /// </summary>
 public static void SetDropScrollingMode(UIElement target, ScrollingMode value)
 {
     target.SetValue(DropScrollingModeProperty, value);
 }
Beispiel #3
0
        /// <summary>
        /// Make a view visible into a scroll view
        /// </summary>
        /// <param name="scrollView">The scroll view to scroll to get the item visible.</param>
        /// <param name="view">View to make visible.</param>
        /// <param name="mode">Specifies a mode to use to place the view into the view port.</param>
        /// <param name="padding">
        /// Add an extra margin to the view from the edge of the view port when mode is
        /// <seealso cref="BringIntoViewMode.TopLeftOfViewPort"/> or <seealso cref="BringIntoViewMode.BottomRightOfViewPort"/>.
        /// </param>
        /// <param name="animationMode">Specifies animation mode to use to animate the scrolling (or not).</param>
        public static void BringIntoView(
            this UIScrollView scrollView,
            UIView view,
            BringIntoViewMode mode      = BringIntoViewMode.ClosestEdge,
            int padding                 = 0,
            ScrollingMode animationMode = ScrollingMode.Forced)
        {
            var boundsOfViewInScrollViewCoordinatesSystem = scrollView.ConvertRectFromView(view.Bounds, view);
            var bounds   = scrollView.Bounds;
            var inset    = scrollView.ContentInset;
            var viewPort = new CGRect
                           (
                bounds.X + inset.Left,
                bounds.Y + inset.Top,
                bounds.Width - inset.Left - inset.Right,
                bounds.Height - inset.Top - inset.Bottom
                           );

            nfloat x, y;

            switch (mode)
            {
            case BringIntoViewMode.ClosestEdge:
                scrollView.ScrollRectToVisible(boundsOfViewInScrollViewCoordinatesSystem, animationMode != ScrollingMode.NotAnimated);
                return;

            case BringIntoViewMode.TopLeftOfViewPort:
                x = boundsOfViewInScrollViewCoordinatesSystem.Left - padding;
                y = boundsOfViewInScrollViewCoordinatesSystem.Top - padding;
                break;

            case BringIntoViewMode.CenterOfViewPort:
                x = boundsOfViewInScrollViewCoordinatesSystem.Left - (viewPort.Width / 2) + (boundsOfViewInScrollViewCoordinatesSystem.Width / 2);
                y = boundsOfViewInScrollViewCoordinatesSystem.Top - (viewPort.Height / 2) + (boundsOfViewInScrollViewCoordinatesSystem.Height / 2);
                break;

            case BringIntoViewMode.BottomRightOfViewPort:
                x = boundsOfViewInScrollViewCoordinatesSystem.Right - viewPort.Width + padding;
                y = boundsOfViewInScrollViewCoordinatesSystem.Bottom - viewPort.Height + padding;
                break;

            default:
                throw new NotSupportedException("Unknown scroll into view behavior");
            }

            var maxX = scrollView.ContentSize.Width - viewPort.Width;
            var maxY = scrollView.ContentSize.Height - viewPort.Height;

            x = (nfloat)Math.Max(0, (nfloat)Math.Min(maxX, x));
            y = (nfloat)Math.Max(0, (nfloat)Math.Min(maxY, y));

            switch (animationMode)
            {
            case ScrollingMode.NotAnimated:
                scrollView.SetContentOffset(new CGPoint(x, y), false);
                break;


            case ScrollingMode.Animated:
                scrollView.SetContentOffset(new CGPoint(x, y), true);
                break;

            case ScrollingMode.Forced:
                scrollView.ContentOffset = new CGPoint(x, y);
                break;

            default:
                throw new NotSupportedException("Unknown animation mode");
            }
        }
Beispiel #4
0
 public ScrollRequest(int pageSize, int firstIndex)
 {
     PageSize   = pageSize;
     FirstIndex = firstIndex;
     Mode       = ScrollingMode.User;
 }
Beispiel #5
0
 public ScrollRequest(int pageSize)
 {
     PageSize = pageSize;
     Mode     = ScrollingMode.Tail;
 }
Beispiel #6
0
        private static void InvalidateScrollMode(object propertyOwner, PropertyKey <ScrollingMode> propertyKey, ScrollingMode propertyOldValue)
        {
            var element = (ScrollViewer)propertyOwner;

            element.OnScrollModeChanged();
        }
Beispiel #7
0
 public ScrollRequest(ScrollingMode mode, int pageSize, int firstIndex)
 {
     PageSize   = pageSize;
     FirstIndex = firstIndex;
     Mode       = mode;
 }