In WPF how do I add easing function to my animation from code behind?

Vitalij picture Vitalij · Sep 15, 2010 · Viewed 8.6k times · Source

I am creating doubleAniation in code and I want to add an easing function to it, so how do I do it?

Answer

Conrad picture Conrad · Jun 19, 2013

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);