Create a Storyboard Programatically

I’ve just created my first Storyboard outside of Blend so I thought I break down the code and save it for reference

            // Create a duration of .5 seconds.
            Duration duration = new Duration(TimeSpan.FromMilliseconds(500));

            //Create two DoubleAnimationsUsingKeyFrame and set their properties.
            DoubleAnimationUsingKeyFrames myDoubleAnimation1 = new DoubleAnimationUsingKeyFrames();
            myDoubleAnimation1.Duration = duration;

            //Create an EasingDoubleKeyFrame
            EasingDoubleKeyFrame WidthChange = new EasingDoubleKeyFrame();
            WidthChange.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500));
            WidthChange.Value = DblHeight;
            CircleEase EsEase = new CircleEase();
            EsEase.EasingMode = EasingMode.EaseInOut;
            WidthChange.EasingFunction = EsEase;

            Storyboard sb = new Storyboard();
            sb.Duration = duration;


            //I don't know why but Targets are set with a static method in the Storyboard class
            Storyboard.SetTarget(myDoubleAnimation1, AnimationTarget);
            Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(FrameworkElement.Width)"));

            return sb;
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: