WPF DoubleAnimation播放顺序
有两个DoubleAnimation da1, da2, 他们的Duration属性不确定(时间长短不确定)
有四个Rectangle rect1, rect2, rect3, rect4,对每个rect进行透明度的变化,从1到0
- C# code
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);
代码执行之后,我想知道,那个Rectangle最先动作完毕(透明度变成了0),然后做进一步的其他操作。
请问我需要怎么实现呢?我在DoubleAnimation里边找到了Completed事件,但是他的sender参数是AnimationClock类型的,我也没办法从这个sender中找到他对应的da<i>或者rect<i>,请问能指点一下么?谢谢
[解决办法]
刚测试过了没问题
- C# code
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; } }