2013-02-10 5 views
1

Visual3D 요소가 포함 된 사용자 정의 3D 모델 클래스 (Model)와 해당 모델과 관련된 애니메이션을 포함하는 Storyboard (sb)이 있습니다. Storyboard을 사용하여 Visual3D 요소를 회전하려고하지만 불행히도 작동하지 않습니다.WPF 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(); 

    } 

답변

3

문제는 this answer에서 설명 니펫이다.

Storyboard.SetTarget을 사용하는 대신 변환 이름을 등록하고 Storyboard.SetTargetName을 호출해야합니다. 또한 Storyboard.Begin(FrameworkElement)을 호출하고 해당 이름 범위가있는 FrameworkElement를 매개 변수로 전달해야합니다 (여기서 this).

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

또한 당신이 어딘가에 스토리 보드의 어린이를 지우거나 애니메이션이 시작될 때마다 새로운 스토리 보드를 작성해야합니다 같아요.

+0

그것은 작동합니다. 회신 할 시간을내어 주신 Clemens에게 감사드립니다 !!! – Raathigesh

관련 문제