Reputation: 4625
I am creating doubleAniation in code and I want to add an easing function to it, so how do I do it?
Upvotes: 1
Views: 9627
Reputation: 2359
It's not necessary to use DoubleAnimationUsingKeyFrames
- it can be done with just DoubleAnimation
:
CircleEase easing = new CircleEase(); // or whatever easing class you want
easing.EasingMode = EasingMode.EaseInOut;
DoubleAnimation scrollQueue = new DoubleAnimation();
scrollQueue.By = -singleScrollAmt;
scrollQueue.EasingFunction = easing;
scrollQueue.Duration = TimeSpan.FromSeconds(0.5);
MyTextBlock.BeginAnimation(Canvas.TopProperty, scrollQueue);
Upvotes: 11
Reputation: 3830
Here's how I do it:
DoubleAnimationUsingKeyFrames compassRoseAnimation = new DoubleAnimationUsingKeyFrames();
compassRoseAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));
QuarticEase easingFunction = new QuarticEase();
easingFunction.EasingMode = EasingMode.EaseInOut;
EasingDoubleKeyFrame startAnimation = new EasingDoubleKeyFrame(previousRotationDegrees, KeyTime.FromPercent(0));
EasingDoubleKeyFrame endAnimation = new EasingDoubleKeyFrame(newRotationDegrees, KeyTime.FromPercent(1.0), easingFunction);
compassRoseAnimation.KeyFrames.Add(startAnimation);
compassRoseAnimation.KeyFrames.Add(endAnimation);
RotateTransform rotateTransform = new RotateTransform();
CompassWithNumbersControl.RenderTransform = rotateTransform;
rotateTransform.BeginAnimation(RotateTransform.AngleProperty, compassRoseAnimation);
Upvotes: 5
Reputation: 4625
I have figure out it myself. I was looking for Easing property, but in fact it is called KeySpline and I have to use DoubleAniamtionUsingKeyFrames instead, to get easing functionality.
Upvotes: -1