情节提要动画错误 [英] Storyboard Animation Error
本文介绍了情节提要动画错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
人们:)我正在尝试一个在线学习的教程,该教程根据三个可调节旋转,距离和持续时间的滑块控件来为对象设置动画.这是我后面的代码:
Hi people :) i''m trying a tutorial i found online to animate an object according to three slider controls that adjust rotation, distance and duration. Here''s my code behind :
//address the storyboard by its name
Storyboard sb = (Storyboard)this.FindResource("RectangleAnimation");
//search for the two DoubleAnimationUsingKeyFrames elements in the storyboard
DoubleAnimationUsingKeyFrames translate = (DoubleAnimationUsingKeyFrames)sb.Children[0];
DoubleAnimationUsingKeyFrames rotate = (DoubleAnimationUsingKeyFrames)sb.Children[1];
//search for the two splinedoublekeyframe elements in the storyboard
SplineDoubleKeyFrame translateFrame = (SplineDoubleKeyFrame)translate.KeyFrames[0];
SplineDoubleKeyFrame rotateFrame = (SplineDoubleKeyFrame)rotate.KeyFrames[0];
//duration: adjust the property keytime to the value of the slider sldDuration
translateFrame.KeyTime = new TimeSpan(0, 0, (int)sldDuration.Value);
rotateFrame.KeyTime = new TimeSpan(0, 0, (int)sldDuration.Value);
//rotation: adjust the property Value of the rotateFrame to he value of te lsider sldrotation
rotateFrame.Value = sldRotation.Value;
//distance:adjust the property value of the translateFrame to the value of the slider sldDistance
translateFrame.Value = sldDistance.Value;
//finally start the animation
sb.Begin(this);
但我在
收到此错误
but i get this error at
SplineDoubleKeyFrame translateFrame = (SplineDoubleKeyFrame)translate.KeyFrames[0];
saying: Unable to cast object of type ''System.Windows.Media.Animation.EasingDoubleKeyFrame'' to type ''System.Windows.Media.Animation.SplineDoubleKeyFrame''.
谁能告诉我我做错了吗?
谢谢大家
Can anyone tell me what i''m doing wrong?
Thanks all
推荐答案
>>谁能告诉我我做错了什么吗?
尝试将EasingDoubleKeyFrame强制转换为SplineDoubleKeyFrame,就像异常消息状态一样:)
如果您不知道数组中关键帧的类型,则可以使用基类DoubleKeyFrame代替SplineDoubleKeyFrame.
>>Can anyone tell me what i''m doing wrong?
Trying to cast a EasingDoubleKeyFrame to a SplineDoubleKeyFrame, just like the exception message states :)
If you don''t know the type of keyframes that are in the array, then maybe you can use the base class DoubleKeyFrame instead of SplineDoubleKeyFrame.
这篇关于情节提要动画错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文