private void Clear() { _selectedIndex = -1; _minTranslationX = 0.0; _maxTranslationX = 0.0; _translationX = 0.0; _previousImage = null; _currentImage = null; _nextImage = null; }
public void Move(double percent) { percent = PanAndZoomBehavior.Clamp(percent, -1.0, 1.0); var translateX = percent < 0.0 ? _translationX - (_minTranslationX - _translationX) * percent : _translationX + (_maxTranslationX - _translationX) * percent; //Transform.X = translateX; if (_currentImage != null) { _currentImage.Width = _currentImage.ExpandedWidth - (_currentImage.ExpandedWidth - RibbonImageControl.MinExpandedWidth) * Math.Abs(percent); } _toImage = percent < 0.0 ? _nextImage : _previousImage; if (_toImage != null) { _toImage.Width = RibbonImageControl.MinExpandedWidth + (_toImage.ExpandedWidth - RibbonImageControl.MinExpandedWidth) * Math.Abs(percent); } _toContainer = percent < 0.0 ? _nextContainer : _previousContainer; var x = 0.0; for (var i = 0; i < Items.Items.Count; i++) { ContentPresenter container; var image = FindAtIndex <RibbonImageControl>(Items, i, out container); if (container != null) { container.RenderTransform = new TranslateTransform { X = x + translateX }; x += image.Width; //if (container == _toContainer) //{ // x += _toImage.Width; //} //else if (container == _currentContainer) //{ // x += _currentImage.Width; //} //else if (container != null) //{ // x += image.Width; //} } } }
public bool ScrollTo(int index, double duration) { if (index == _selectedIndex) { AnimatePosition(_currentImage, _currentImage != null ? _currentImage.ExpandedWidth : RibbonImageControl.MinExpandedWidth, _toImage, RibbonImageControl.MinExpandedWidth, Transform, _translationX, duration); return(true); } ContentPresenter fromContainer; ContentPresenter toContainer; var fromItem = FindAtIndex <RibbonImageControl>(Items, _selectedIndex, out fromContainer); var toItem = FindAtIndex <RibbonImageControl>(Items, index, out toContainer); if (toItem == null) { var translationX = index > _selectedIndex ? _minTranslationX : _maxTranslationX; AnimatePosition(fromItem, RibbonImageControl.MinExpandedWidth, null, 0, Transform, translationX, duration); return(false); } _selectedIndex = index; _previousImage = FindAtIndex <RibbonImageControl>(Items, _selectedIndex - 1, out _previousContainer); _currentImage = toItem; _currentContainer = toContainer; _nextImage = FindAtIndex <RibbonImageControl>(Items, _selectedIndex + 1, out _nextContainer); _minTranslationX = -(_selectedIndex + 1) * RibbonImageControl.MinExpandedWidth - (_nextImage != null ? _nextImage.ExpandedWidth / 2.0 : RibbonImageControl.MaxExpandedWidth / 2.0); _maxTranslationX = -(_selectedIndex - 1) * RibbonImageControl.MinExpandedWidth - (_previousImage != null ? _previousImage.ExpandedWidth / 2.0 : RibbonImageControl.MinExpandedWidth - RibbonImageControl.MaxExpandedWidth / 2.0); _translationX = -(RibbonImageControl.MinExpandedWidth * index + toItem.ExpandedWidth / 2.0); AnimatePosition(fromItem, RibbonImageControl.MinExpandedWidth, toItem, toItem.ExpandedWidth, Transform, -(RibbonImageControl.MinExpandedWidth * index + toItem.ExpandedWidth / 2.0), duration); return(true); }
private void AnimatePosition(RibbonImageControl currentControl, double currentWidth, RibbonImageControl nextControl, double nextWidth, TranslateTransform transform, double translateXAll, double duration) { var storyboard = new Storyboard(); //#if EXTENDED_LENGTH if (currentControl != null) { var currentWidthAnimation = new DoubleAnimation(); currentWidthAnimation.To = currentWidth; currentWidthAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); Storyboard.SetTarget(currentWidthAnimation, currentControl); Storyboard.SetTargetProperty(currentWidthAnimation, new PropertyPath("Width")); storyboard.Children.Add(currentWidthAnimation); } if (nextControl != null && nextControl != currentControl) { var nextWidthAnimation = new DoubleAnimation(); nextWidthAnimation.To = nextWidth; nextWidthAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); Storyboard.SetTarget(nextWidthAnimation, nextControl); Storyboard.SetTargetProperty(nextWidthAnimation, new PropertyPath("Width")); storyboard.Children.Add(nextWidthAnimation); } //#endif //var translateXAnimation = new DoubleAnimation(); //translateXAnimation.To = translateX; //translateXAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); //Storyboard.SetTarget(translateXAnimation, transform); //Storyboard.SetTargetProperty(translateXAnimation, new PropertyPath("X")); //storyboard.Children.Add(translateXAnimation); var x = 0.0; for (var i = 0; i < Items.Items.Count; i++) { ContentPresenter container; var image = FindAtIndex <RibbonImageControl>(Items, i, out container); if (container != null) { var animation = new DoubleAnimation(); animation.To = x + translateXAll; animation.Duration = new Duration(TimeSpan.FromSeconds(duration)); Storyboard.SetTarget(animation, container.RenderTransform); Storyboard.SetTargetProperty(animation, new PropertyPath("X")); storyboard.Children.Add(animation); //container.RenderTransform = new TranslateTransform { X = x }; //x += image.Width; if (image == currentControl) { x += currentWidth; } else if (image == nextControl) { x += nextWidth; } else if (image != null) { x += image.Width; } } } storyboard.Begin(); }