在WPF中,如何从代码隐藏向动画添加缓和功能?

在WPF中,如何从代码隐藏向动画添加缓和功能?,wpf,animation,easing-functions,Wpf,Animation,Easing Functions,我正在用代码创建双重化,我想给它添加一个放松功能,那么我该怎么做呢?我自己已经弄明白了。我一直在寻找缓和特性,但实际上它被称为KeySpline,我必须使用DoubleAniamtionUsingKeyFrames来获得缓和功能。我自己已经找到了它。我一直在寻找放松属性,但实际上它被称为KeySpline,我必须使用DoubleAniamtionUsingKeyFrames来获得放松功能。我是这样做的: DoubleAnimationUsingKeyFrames compassR

我正在用代码创建双重化,我想给它添加一个放松功能,那么我该怎么做呢?

我自己已经弄明白了。我一直在寻找缓和特性,但实际上它被称为KeySpline,我必须使用DoubleAniamtionUsingKeyFrames来获得缓和功能。

我自己已经找到了它。我一直在寻找放松属性,但实际上它被称为KeySpline,我必须使用DoubleAniamtionUsingKeyFrames来获得放松功能。

我是这样做的:

        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);
我是这样做的:

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

无需使用关键帧使用双动画-只需使用双动画即可:

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

无需使用关键帧使用双动画-只需使用双动画即可:

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

你根本不需要使用关键帧-有两个完全有效的答案,你没有给予信任,而是用一个糟糕的答案回答了你自己的问题。就你而言,社区之间的互动非常糟糕。原始问题的措辞也很糟糕,定义/约束也很糟糕,并且没有任何示例代码来演示您的问题。您根本不需要使用关键帧-有两个完全有效的答案,您没有给予信任,而是用错误的解决方案回答了您自己的问题。就你而言,社区之间的互动非常糟糕。原始问题的措辞也很糟糕,定义/约束也很糟糕,没有任何示例代码来演示您的问题。嗯,如果我错了,请纠正我,但是您的代码中是否有拼写错误?您可以定义,然后在您的QuadraticEase上设置EasingMode,但实际上看起来您并没有使用它。你到底在哪里把它应用到你的动画中?@MarqueIV:Line 6我真的很困惑为什么他**我错过了这个!我想我是在一个小屏幕上看的,那部分被剪掉了,我没有注意到。忽略我的评论!:-)如果我错了,请纠正我,但是你的代码有错吗?您可以定义,然后在您的QuadraticEase上设置EasingMode,但实际上看起来您并没有使用它。你到底在哪里把它应用到你的动画中?@MarqueIV:Line 6我真的很困惑为什么他**我错过了这个!我想我是在一个小屏幕上看的,那部分被剪掉了,我没有注意到。忽略我的评论!:-)