none
[Codebehind] Animating a grid on load form RRS feed

  • Question

  • Hey everyone, 

    A 'simple' question regarding animating controls in WPF. 

    I've added a grid control to the form and in code I do this:

            private void LoadUI()
            {
                Storyboard myStoryboard = new Storyboard();
                
                myStoryboard.Children.Add(CreateAnimation(0, 55, new Duration(TimeSpan.FromSeconds(0.5)), TimeSpan.FromSeconds(0), HeaderCanvas.Name, Grid.HeightProperty));
               
                //myStoryboard.Completed += new EventHandler(myStoryboard_Completed);
                myStoryboard.Begin(this);
            }
    
            private DoubleAnimation CreateAnimation(double from, double to, Duration duration, TimeSpan begin, string name, DependencyProperty controlProperty)
            {
                DoubleAnimation myDoubleAnimation = new DoubleAnimation();
                myDoubleAnimation.From = from;
                myDoubleAnimation.To = to;
                myDoubleAnimation.Duration = duration;
                myDoubleAnimation.BeginTime = begin;
                System.Windows.Media.Animation.ExponentialEase b = new ExponentialEase();
                b.EasingMode = EasingMode.EaseOut;
                myDoubleAnimation.EasingFunction = b;
                Storyboard.SetTargetName(myDoubleAnimation, name);
                Storyboard.SetTargetProperty(myDoubleAnimation,
                    new PropertyPath(controlProperty));
                return myDoubleAnimation;
            }
    

    Now the grid does animate when the form is loaded, however 'starts' at the center of the object and goes up and down to the correct size. 

    I'd rather have it just coming down. 

    Kinda like in this video, 1m16sec  http://www.youtube.com/watch?v=Zp-_oUwdSeY&feature=related.

    Thanks for your help!

    Tobias

     

    Thursday, January 26, 2012 1:41 PM

Answers