Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 25-Jul-11 20:33pm
v2

1 solution

>>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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900