WPF DoubleAnimation播放顺序
有两个DoubleAnimation da1, da2, 他们的Duration属性不确定(时间长短不确定)
有四个Rectangle rect1, rect2, rect3, rect4,对每个rect进行透明度的变化,从1到0
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; } }