I am having a slight problem sliding controls on a form with C# code. So far I found this article http://vbcity.com/blogs/xtab/archive...on-in-wpf.aspx on how to do it with XAML, but I need to do it with C# because items will only slide to places depending on what item is selected in a textbox.

I have my controls setup like this:


On the left is how it should look with item one selected, and on the right is how it should look with item 2 selected. With the textbox gone the height of the form will also reduce as well and when it comes back (item 1) it will increase.

The code I tried so far is this, but it doesn't seem to work so I must be doing something wrong but don't know what as I am fairly new to WPF.

Code:
Storyboard storyboard = new Storyboard();
            TimeSpan duration = new TimeSpan(0, 0, 3);
 
            DoubleAnimation animation = new DoubleAnimation();
            //animation.From = 0.0;
            //animation.To = 1.0;
            animation.By = 100;
            animation.Duration = new Duration(duration);
 
            Storyboard.SetTargetName(animation, btnTest.Name);
            Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.XProperty));
 
            storyboard.Children.Add(animation);
 
            storyboard.Begin(this);