Dans WPF comment puis-je ajouter à mon fonction d'accélération animation à partir du code derrière?

StackOverflow https://stackoverflow.com/questions/3719597

  •  03-10-2019
  •  | 
  •  

Question

Je crée doubleAniation dans le code et je veux ajouter une fonction à faciliter, alors comment puis-je faire?

Était-ce utile?

La solution

Voici comment je le fais:

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

Autres conseils

Il est pas nécessaire d'utiliser DoubleAnimationUsingKeyFrames - il peut être fait avec juste 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);

Je figure sur moi-même. Je cherchais la propriété Easing, mais en fait, il est appelé KeySpline et je dois utiliser à la place DoubleAniamtionUsingKeyFrames, pour obtenir une fonctionnalité d'accélération.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top