在WPF中如何从代码后面添加缓动功能到我的动画?

时间:2010-09-15 16:10:04

标签: wpf animation easing-functions

我在代码中创建了doubleAniation,我想为它添加一个缓动函数,所以我该怎么做?

3 个答案:

答案 0 :(得分:9)

没有必要使用DoubleAnimationUsingKeyFrames - 只需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);

答案 1 :(得分:5)

我是这样做的:

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

答案 2 :(得分:-1)

我自己弄清楚了。我一直在寻找Easing属性,但事实上它被称为KeySpline,我必须使用DoubleAniamtionUsingKeyFrames来获得缓和功能。