internal Storyboard CreateStoryboard(BubbleTaskGroup taskGroup) { if (taskGroup.Count() == 0) { return(null); } int millisecondsPerUnit; Func <ContentPresenter, double> getTo; DependencyProperty animatedProperty; IEnumerable <BubbleViewModel> bubbles; this.GetStoryboardCreationData( taskGroup, out millisecondsPerUnit, out getTo, out animatedProperty, out bubbles); var storyboard = new Storyboard(); var targetProperty = new PropertyPath(animatedProperty); var beginTime = TimeSpan.FromMilliseconds(0); var beginTimeIncrement = TimeSpan.FromMilliseconds(millisecondsPerUnit / bubbles.Count()); foreach (ContentPresenter presenter in this.GetBubblePresenters(bubbles)) { var bubble = presenter.DataContext as BubbleViewModel; var anim = new EasingDoubleAnimation { BeginTime = beginTime, Duration = CalculateDuration(taskGroup, bubble, millisecondsPerUnit), Equation = EasingEquation.CubicEaseIn, To = getTo(presenter), }; Storyboard.SetTarget(anim, presenter); Storyboard.SetTargetProperty(anim, targetProperty); if (IsTaskStaggered(taskGroup.TaskType)) { beginTime = beginTime.Add(beginTimeIncrement); } storyboard.Children.Add(anim); } return(storyboard); }
Storyboard CreateStoryboard( BubblesTask task, int millisecondsPerUnit, Func <ContentPresenter, double> getTo, DependencyProperty animatedProperty, BubbleViewModel[] bubbles) { if (!bubbles.Any()) { return(null); } var storyboard = new Storyboard(); var targetProperty = new PropertyPath(animatedProperty); var beginTime = TimeSpan.FromMilliseconds(0); var beginTimeIncrement = TimeSpan.FromMilliseconds(millisecondsPerUnit / bubbles.Count()); foreach (ContentPresenter presenter in this.GetBubblePresenters(bubbles)) { var bubble = presenter.DataContext as BubbleViewModel; var duration = CalculateDuration(task.TaskType, bubble, millisecondsPerUnit); var to = getTo(presenter); var anim = new EasingDoubleAnimation { BeginTime = beginTime, Duration = duration, Equation = EasingEquation.CubicEaseIn, To = to, }; Storyboard.SetTarget(anim, presenter); Storyboard.SetTargetProperty(anim, targetProperty); if (IsTaskStaggered(task.TaskType)) { beginTime = beginTime.Add(beginTimeIncrement); } storyboard.Children.Add(anim); } return(storyboard); }
void PrepareForRotation(out DoubleAnimation frontAnimation, out DoubleAnimation backAnimation) { Vector3D axis; double delta; switch (this.RotationDirection) { case RotationDirection.LeftToRight: axis = new Vector3D(0, +1, 0); delta = +180; break; case RotationDirection.RightToLeft: axis = new Vector3D(0, +1, 0); delta = -180; break; case RotationDirection.TopToBottom: axis = new Vector3D(+1, 0, 0); delta = +180; break; case RotationDirection.BottomToTop: axis = new Vector3D(+1, 0, 0); delta = -180; break; case RotationDirection.TopLeftToBottomRight: axis = new Vector3D(+1, +1, 0); delta = +180; break; case RotationDirection.TopRightToBottomLeft: axis = new Vector3D(-1, +1, 0); delta = -180; break; case RotationDirection.BottomLeftToTopRight: axis = new Vector3D(-1, +1, 0); delta = +180; break; case RotationDirection.BottomRightToTopLeft: axis = new Vector3D(+1, +1, 0); delta = -180; break; default: throw new ApplicationException("Unrecognized RotationDirection value: " + this.RotationDirection); } _frontRotation.Axis = _backRotation.Axis = axis; frontAnimation = new EasingDoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength)), Equation = _easingEquation, From = _frontRotation.Angle, To = _frontRotation.Angle + delta }; backAnimation = new EasingDoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength)), Equation = _easingEquation, From = _backRotation.Angle, To = _backRotation.Angle + delta }; }