This is my code. GridLenghtAnimation was taken from a project in codeproject :
http://www.codeproject.com/KB/WPF/GridLengthAnimation.aspx
private void ExpandNetworkExplorer()
{
GridLengthAnimation gla = new GridLengthAnimation();
gla.From = new GridLength(0, GridUnitType.Star);
gla.To = new GridLength(0.3, GridUnitType.Star);
gla.Duration = new TimeSpan(0, 0, 0, 0, 200);
mainGrid.ColumnDefinitions[0].BeginAnimation(ColumnDefinition.WidthProperty, gla);
Storyboard sb = new Storyboard();
DoubleAnimation daX = new DoubleAnimation(-networkExplorerBorder.ActualWidth, 0, new Duration(new TimeSpan(0, 0, 0, 0, 200)));
daX.FillBehavior = FillBehavior.HoldEnd;
Storyboard.SetTargetName(daX, TranslateTransformName);
Storyboard.SetTargetProperty(daX, new PropertyPath(TranslateTransform.XProperty));
sb.Children.Add(daX);
//sb.BeginTime = new TimeSpan(0, 0, 0, 0, 150);
sb.Begin(networkExplorerBorder);
// animation for the button rotation
Storyboard rotateButton = (Storyboard)this.FindResource("networkExplorerHideAndShowButtonRotateUp");
this.BeginStoryboard(rotateButton);
networkExplorerHideAndShowMenuItem.Header = "Hide Network Explorer";
networkExplorerVisible = true;
}
private void CollapseNetworkExplorer()
{
// animation for the network explorer x translate
Storyboard sb = new Storyboard();
DoubleAnimation daX = new DoubleAnimation(0, -networkExplorerBorder.ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 200)));
daX.FillBehavior = FillBehavior.HoldEnd;
Storyboard.SetTargetName(daX, TranslateTransformName);
Storyboard.SetTargetProperty(daX, new PropertyPath(TranslateTransform.XProperty));
sb.Children.Add(daX);
sb.Begin(networkExplorerBorder);
// animation for the network explorer column width
GridLengthAnimation gla = new GridLengthAnimation();
gla.From = new GridLength(0.3, GridUnitType.Star);
gla.To = new GridLength(0, GridUnitType.Star);
gla.Duration = new TimeSpan(0, 0, 0, 0, 200);
//gla.BeginTime = new TimeSpan(0, 0, 0, 0, 150);
mainGrid.ColumnDefinitions[0].BeginAnimation(ColumnDefinition.WidthProperty, gla);
// animation for the button rotation
Storyboard rotateButton = (Storyboard)this.FindResource("networkExplorerHideAndShowButtonRotateDown");
this.BeginStoryboard(rotateButton);
networkExplorerHideAndShowMenuItem.Header = "Show Network Explorer";
networkExplorerVisible = false;
}
Thx,
Nuno