Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从代码中使用情节提要时WPF动画问题_Wpf_3d - Fatal编程技术网

从代码中使用情节提要时WPF动画问题

从代码中使用情节提要时WPF动画问题,wpf,3d,Wpf,3d,我正在制作一个包含信息的平面、方形瓷砖的3D旋转木马。我正在制作这个旋转木马的动画,当一个人按下“下一步”和“上一步”按钮时旋转 我在旋转木马上应用了RotateTransform3D的旋转属性,通过使用BeginAnimation使其工作,但我似乎无法使同一动画的故事板版本工作。我之所以需要故事板版本是因为HandOffBehavior.Compose参数,因为如果没有它,多次单击“下一步”和“上一步”按钮会导致旋转木马错位 以下是故事板的代码: RotateTransform3D tempT

我正在制作一个包含信息的平面、方形瓷砖的3D旋转木马。我正在制作这个旋转木马的动画,当一个人按下“下一步”和“上一步”按钮时旋转

我在旋转木马上应用了RotateTransform3D的旋转属性,通过使用BeginAnimation使其工作,但我似乎无法使同一动画的故事板版本工作。我之所以需要故事板版本是因为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);

出于某种原因,此代码完全不会产生任何结果。我不折不扣地遵循我的例子,所以我很沮丧。非常感谢您的帮助。如果我可以复制切换行为,我也完全愿意使用BeginAnimation。Compose。

我的经验来自2D动画,但我想问题也是一样的

出于某些愚蠢的原因(可能与不健康地关注XAML有关),故事板只能通过按名称查找对象来设置可自由化对象的动画。(请参见中的示例。)因此,尽管在调用Storyboard.SetTarget(动画、旋转)时提供了对“旋转”对象的引用,但故事板只希望记住并使用它没有的名称

解决办法是:

  • 围绕将控制转换的元素创建命名范围
  • 为每个正在设置动画的可冻结对象调用RegisterName()
  • 将元素传递给故事板。开始()
这将使您的代码看起来像这样(未经测试):

这些在XAML中都不是必需的,因为对象是自动注册的

编辑:但后来我发现,你可以通过完全省略故事板来简化事情:

var T = new TranslateTransform(40, 0);
Duration duration = new Duration(new TimeSpan(0, 0, 0, 1, 0);
DoubleAnimation anim = new DoubleAnimation(30, duration);
T.BeginAnimation(TranslateTransform.YProperty, anim);

我认为你应该接受奥利弗的回答。如果将
Storyboard.SetTarget(动画,旋转)
替换为
Storyboard.SetTargetName(动画,旋转)
,则此功能有效。另请参见.replace Storyboard.SetTarget(动画,旋转)与Storyboard.SetTargetName(动画,“旋转”)。
var T = new TranslateTransform(40, 0);
Duration duration = new Duration(new TimeSpan(0, 0, 0, 1, 0);
DoubleAnimation anim = new DoubleAnimation(30, duration);
T.BeginAnimation(TranslateTransform.YProperty, anim);