/// <summary>
/// 设置控件的【大小、背景】动画效果,
/// 高度、宽度默认当前大小,背景默认White~LightGreen
/// </summary>
/// <param name="control">要设置动画的控件</param>
/// <Author> frd 2011-9-8</Author>
public static void SetDoubleAnimation(object control)
{
Type type = control.GetType();
switch (type.Name)
{
case "Image":
{
//更多控件的情况,模仿编写既是
}
break;
case "Border":
{
Border newBorder = (Border)control;
#region 高、宽变化动画
DoubleAnimation widthAnimation = new DoubleAnimation(0, newBorder.Width, new Duration(TimeSpan.FromSeconds(0.5)));
newBorder.BeginAnimation(Border.WidthProperty, widthAnimation, HandoffBehavior.Compose);
DoubleAnimation heightAnimation = new DoubleAnimation(0, newBorder.Height, new Duration(TimeSpan.FromSeconds(0.5)));
newBorder.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
#endregion
#region 背景颜色动画
SolidColorBrush myBrush = new SolidColorBrush();
ColorAnimation myColorAnimation = new ColorAnimation();
myColorAnimation.From = Colors.White;
myColorAnimation.To = Colors.LightGreen;
myColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
myColorAnimation.AutoReverse = true;
myColorAnimation.RepeatBehavior = RepeatBehavior.Forever;
myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation, HandoffBehavior.Compose);
newBorder.Background = myBrush;
#endregion
}
break;
default:
break;
}
}