2

Visual3D 要素を含むカスタム 3D モデル クラス (Model) と、Storyboardそのモデルに関連するアニメーションを保持する (sb) があります。を使用して Visual3D 要素を回転させようとしてStoryboardいますが、残念ながら機能していません。

ここにコードスニペットがあります

public void AnimationRotate(Model model, double duration, double startTime, RepeatBehavior behaviour)
    {

        //Rotate transform 3D
        RotateTransform3D rotateTransform = new RotateTransform3D();

        //assign transform to the model
        model.Visual3D.Transform = Transform3DHelper.CombineTransform(model.Visual3D.Transform, rotateTransform);

        //define the rotation axis
        AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180);

        //create 3D rotation animation
        Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(0.5));

        //rotation behaviour
        rotateAnimation.RepeatBehavior = behaviour;

        //start animation from time
        rotateAnimation.BeginTime = TimeSpan.FromSeconds(startTime);

        //begin animation - THIS WORKS FINE
       // rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);

        Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath(RotateTransform3D.RotationProperty));
        Storyboard.SetTarget(rotateAnimation, rotateTransform);

        //add animation to the storyboard of the model
        model.sb.Children.Add(rotateAnimation);

        //BUT THIS APPROACH IS NOT WOKRING
        model.sb.Begin();

    }
4

1 に答える 1

5

問題はこの回答で説明されています。

を使用する代わりにStoryboard.SetTarget、変換の名前を登録して を呼び出す必要がありますStoryboard.SetTargetNameさらに、 Storyboard.Begin(FrameworkElement)を呼び出し、FrameworkElement をパラメーターとして適切な名前スコープで渡す必要があります (thisここ)。

RegisterName("RotateTransform", rotateTransform);
Storyboard.SetTargetName(rotateAnimation, "RotateTransform");
...
model.sb.Begin(this);

また、ストーリーボードの子をどこかでクリアするか、アニメーションが開始されるたびに新しいストーリーボードを作成する必要があると思います。

于 2013-02-10T09:54:47.220 に答える