"GridLengthAnimation" , found it! =)
http://www.codeproject.com/KB/WPF/GridLengthAnimation.aspx
This code works better :
Usage :
GridAnimation GA = new GridAnimation();
double GRH = GRIDMAIN.RowDefinitions[MyVariables.INDEX_ROW_TopMenu].ActualHeight;
GA.From = new GridLength(GRH, GridUnitType.Pixel);
GA.To = new GridLength(expanderTopMenu.ActualHeight, GridUnitType.Pixel);
GA.Duration = new Duration(TimeSpan.FromSeconds(.25));
GRIDMAIN.RowDefinitions[MyVariables.INDEX_ROW_TopMenu].BeginAnimation(RowDefinition.HeightProperty, GA);
internal class GridAnimation : AnimationTimeline {
static GridAnimation() {
FromProperty = DependencyProperty.Register("From", typeof(GridLength),
typeof(GridAnimation));
ToProperty = DependencyProperty.Register("To", typeof(GridLength),
typeof(GridAnimation));
}
//**********************************************************************
public override Type TargetPropertyType {
get {
return typeof(GridLength);
}
}
//**********************************************************************
protected override System.Windows.Freezable CreateInstanceCore() {
return new GridAnimation();
}
//**********************************************************************
public static readonly DependencyProperty FromProperty;
public GridLength From {
get {
return (GridLength)GetValue(GridAnimation.FromProperty);
}
set {
SetValue(GridAnimation.FromProperty, value);
}
}
//**********************************************************************
public static readonly DependencyProperty ToProperty;
public GridLength To {
get {
return (GridLength)GetValue(GridAnimation.ToProperty);
}
set {
SetValue(GridAnimation.ToProperty, value);
}
}
//**********************************************************************
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) {
double fromValue = ((GridLength)GetValue(GridAnimation.FromProperty)).Value;
double toValue = ((GridLength)GetValue(GridAnimation.ToProperty)).Value;
if (fromValue > toValue) {
return new GridLength((1 - animationClock.CurrentProgress.Value) * (fromValue - toValue) + toValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
} else {
return new GridLength((animationClock.CurrentProgress.Value) * (toValue - fromValue) + fromValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
}
}
//**********************************************************************
}