【发布时间】:2010-12-31 10:00:17
【问题描述】:
我正在制作一个包含信息的扁平方形瓷砖的 3D 旋转木马。我正在为这个轮播设置动画,使其在一个人按下下一个和上一个按钮时旋转。
我已经通过在应用于轮播的 RotateTransform3D 的 Rotation 属性上使用 BeginAnimation 来使其工作,但我似乎无法使相同动画的 Storyboard 版本工作。我需要 Storyboard 版本的原因是 HandOffBehavior.Compose 参数,因为没有它,多次单击我的下一个和上一个按钮会导致轮播不对齐。
这是情节提要的代码:
RotateTransform3D tempTransform = (RotateTransform3D)wheel.Transform;
AxisAngleRotation3D rotation = (AxisAngleRotation3D)tempTransform.Rotation;
Storyboard storyboard = new Storyboard();
DoubleAnimation animation = new DoubleAnimation();
animation.By = defaultAngle;
animation.Duration = TimeSpan.FromSeconds(.5);
Storyboard.SetTarget(animation, rotation);
Storyboard.SetTargetProperty(animation, new PropertyPath("Angle"));
storyboard.Children.Add(animation);
storyboard.Duration = animation.Duration;
storyboard.Begin(new FrameworkContentElement(), HandoffBehavior.Compose);
由于某种原因,这段代码完全没有结果。我遵循了我必须信中的例子,所以我很沮丧。任何帮助是极大的赞赏。如果我可以复制 HandOffBehavior.Compose,我也完全愿意使用 BeginAnimation。
【问题讨论】:
-
我认为你应该接受奥利弗的回答。如果将
Storyboard.SetTarget(animation, rotation)替换为Storyboard.SetTargetName(animation, "rotation"),它将起作用。另见this。