1

私は にrotatingbuttonます。問題なく動作click180 degreeています

AnimationServices.RotationAnimation((FrameworkElement)sender, 180, 1, "Y"); // working

しかし、同じことを90度の角度rotatingで2回行うと、機能しなくなります

AnimationServices.RotationAnimation((FrameworkElement)sender, 90, 1, "Y");
AnimationServices.RotationAnimation((FrameworkElement)sender, 90, 1, "Y");  // not working

その唯一rotating90 degree角度で

誰かがこの奇妙な問題について何か考えを持っていますか?

アップデート

internal static void RotationAnimation(FrameworkElement sender, int Angle, int DurationInMSec, String Axis)
        {
            var storyboard = new Storyboard();

            var easingDoubleKeyFrame1 = new EasingDoubleKeyFrame
            {
                KeyTime = TimeSpan.FromMilliseconds(0),
                Value = 0
            };

            var easingDoubleKeyFrame2 = new EasingDoubleKeyFrame
            {
                KeyTime = TimeSpan.FromMilliseconds(DurationInMSec),
                Value = Angle
            };

            var doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();

            doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame1);
            doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame2);

            var rotateTransform = new PlaneProjection();

            var button = (FrameworkElement)sender;
            button.Projection = rotateTransform;

            Storyboard.SetTarget(doubleAnimationUsingKeyFrames, rotateTransform);
            Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath("Rotation" + Axis));
            storyboard.Children.Add(doubleAnimationUsingKeyFrames);
            storyboard.Begin();
        }
4

1 に答える 1

1

メソッドのコードを提供しないと、何が起こっているのかわかりませんRotationAnimation。それでも、このメソッドが同じアニメーションを同時に 2 回実行しようとしている可能性は非常に高いです。したがって、同じ要素を 0 度から 90 度まで回転させようとする 2 つのアニメーションがあります。これは... 90度です。現在実行中のアニメーションの回転角度を変更するか、現在のアニメーションの実行が終了するまで待ってから、新しいアニメーションを開始してください。2 つの異なるアニメーションに同じプロパティを同時にアニメーション化するように要求しても、一貫した結果が得られない可能性があります。

編集:あなたのコードを見た後、それは確かに問題です。0 度から 90 度まで回転する 2 つのアニメーションを作成しています。2 つのアニメーションをチェーンし、「origin」パラメーターをメソッドに追加して、2 番目のアニメーションが (0 からではなく) 90° から回転を開始するようにする必要があります。アニメーションを連鎖させるには、作成したアニメーションを返すようにメソッドを変更してから、Completedイベントをサブスクライブします。

そんな感じ:

internal static Storyboard RotationAnimation(FrameworkElement sender, int origin, int Angle, int DurationInMSec, String Axis)
{
    var storyboard = new Storyboard();

    var easingDoubleKeyFrame1 = new EasingDoubleKeyFrame
    {
        KeyTime = TimeSpan.FromMilliseconds(0),
        Value = origin
    };

    var easingDoubleKeyFrame2 = new EasingDoubleKeyFrame
    {
        KeyTime = TimeSpan.FromMilliseconds(DurationInMSec),
        Value = Angle + origin
    };

    var doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();

    doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame1);
    doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame2);

    var rotateTransform = new PlaneProjection();

    var button = (FrameworkElement)sender;
    button.Projection = rotateTransform;

    Storyboard.SetTarget(doubleAnimationUsingKeyFrames, rotateTransform);
    Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath("Rotation" + Axis));
    storyboard.Children.Add(doubleAnimationUsingKeyFrames);
    storyboard.Begin();

    return storyboard;
}

次に、次のように呼び出すことができます。

var storyboard = RotateAnimation((FrameworkElement)sender, 0, 90, 1, "Y");
storyboard.Completed += (s, e) => RotateAnimation((FrameworkElement)sender, 90, 90, 1, "Y");
于 2013-06-10T07:32:22.943 に答える