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); }
protected virtual void OnPositionChanged(PositionChangedEventArgs e) { PositionChangedEventHandler handler = PositionChanged; handler?.Invoke(this, e); }