Пример #1
0
        void UpdateInitialPosition()
        {
            int itemCount = 0;
            int position;

            if (Carousel.CurrentItem != null)
            {
                var carouselEnumerator = Carousel.ItemsSource.GetEnumerator();
                var items = new List <object>();

                while (carouselEnumerator.MoveNext())
                {
                    items.Add(carouselEnumerator.Current);
                    itemCount++;
                }

                position          = items.IndexOf(Carousel.CurrentItem);
                Carousel.Position = position;
            }
            else
            {
                position = Carousel.Position;
            }

            _oldPosition = position;

            SetCurrentItem(_oldPosition);

            var index = Carousel.Loop ? LoopedPosition(itemCount) + _oldPosition : _oldPosition;

            ScrollHelper.JumpScrollToPosition(index, Microsoft.Maui.Controls.ScrollToPosition.Center);
            _gotoPosition = -1;
        }
Пример #2
0
        protected override void ScrollTo(ScrollToRequestEventArgs args)
        {
            var position = DetermineTargetPosition(args);

            if (_carouselViewLoopManager == null)
            {
                return;
            }

            // Special case here
            // We could have a race condition where we are scrolling our collection to center the first item
            // And at the same time the user is requesting we go to a particular item
            if (position == -1)
            {
                if (Carousel.Loop)
                {
                    _carouselViewLoopManager.AddPendingScrollTo(args);
                }

                return;
            }

            if (args.IsAnimated)
            {
                ScrollHelper.AnimateScrollToPosition(position, args.ScrollToPosition);
            }
            else
            {
                ScrollHelper.JumpScrollToPosition(position, args.ScrollToPosition);
            }
        }
Пример #3
0
        protected virtual void ScrollTo(ScrollToRequestEventArgs args)
        {
            if (ItemsView == null)
            {
                return;
            }

            var position = DetermineTargetPosition(args);

            if (args.IsAnimated)
            {
                ScrollHelper.AnimateScrollToPosition(position, args.ScrollToPosition);
            }
            else
            {
                ScrollHelper.JumpScrollToPosition(position, args.ScrollToPosition);
            }
        }