예제 #1
0
        public void SetPosition(int position)
        {
            int oldPosition = _position;

            var positionChangingArgs = new PositionChangingEventArgs()
            {
                Canceled    = false,
                NewPosition = position,
                OldPosition = oldPosition
            };

            OnPositionChanging(ref positionChangingArgs);

            if (positionChangingArgs != null && positionChangingArgs.Canceled)
            {
                return;
            }

            if (position >= 0 && position < ItemSource.Count)
            {
                for (int i = 0; i < ItemSource.Count; i++)
                {
                    ItemSource[i].IsCurrent = i == position;
                }

                _carouselView.PositionSelected -= _carouselView_PositionSelected;
                _carouselView.Position          = position;
                _carouselView.PositionSelected += _carouselView_PositionSelected;

                _position = position;
            }

            var positionChangedArgs = new PositionChangedEventArgs()
            {
                NewPosition = _position,
                OldPosition = oldPosition
            };

            OnPositionChanged(positionChangedArgs);
        }
예제 #2
0
        protected virtual void OnPositionChanged(PositionChangedEventArgs e)
        {
            PositionChangedEventHandler handler = PositionChanged;

            handler?.Invoke(this, e);
        }