日期:2014-05-18 浏览次数:21218 次
da1 = new DoubleAnimation();
duration = new Duration(TimeSpan.FromMilliseconds(getRandomTime())); // getRandomTime()返回随机的ms时间
da1.Duration = duration;
da1.From = 1;
da1.To = 0;
rect1.BeginAnimation(Rectangle.Opacity, da1);
da2 = new DoubleAnimation();
duration = new Duration(TimeSpan.FromMilliseconds(getRandomTime())); // getRandomTime()返回随机的ms时间
da2.Duration = duration;
da2.From = 1;
da2.To = 0;
rect2.BeginAnimation(Rectangle.Opacity, da2);
da1 = new DoubleAnimation();
duration = new Duration(TimeSpan.FromMilliseconds(getRandomTime())); // getRandomTime()返回随机的ms时间
da1.Duration = duration;
da1.From = 1;
da1.To = 0;
rect3.BeginAnimation(Rectangle.Opacity, da1);
da2 = new DoubleAnimation();
duration = new Duration(TimeSpan.FromMilliseconds(getRandomTime())); // getRandomTime()返回随机的ms时间
da2.Duration = duration;
da2.From = 1;
da2.To = 0;
rect4.BeginAnimation(Rectangle.Opacity, da2);
da1 = new DoubleAnimation();
da1.Name = "da1"; //先给个名字
duration = new Duration(TimeSpan.FromMilliseconds(getRandomTime())); // getRandomTime()返回随机的ms时间
da1.Duration = duration;
da1.From = 1;
da1.To = 0;
da1.Completed += new EventHandler(da1_Completed);
rect1.BeginAnimation(Rectangle.Opacity, da1);
//在事件中判断名称就行了
void da1_Completed(object sender, EventArgs e)
{
Timeline name = ((AnimationClock)sender).Timeline;
switch (name )
{
case "da1":
执行的方法。。。
break;
case "da2":
执行的方法。。。
break;
}
}