有两个DoubleAnimation da1, da2, 他们的Duration属性不确定(时间长短不确定)
有四个Rectangle rect1, rect2, rect3, rect4,对每个rect进行透明度的变化,从1到0da1 = 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>,请问能指点一下么?谢谢
有四个Rectangle rect1, rect2, rect3, rect4,对每个rect进行透明度的变化,从1到0da1 = 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>,请问能指点一下么?谢谢
Storyboard.SetTarget(...);
Storyboard.SetTargetProperty(...);
_storyboard.Children.Add(...); // _stoaryboard是Storyboard的一个实例// add other animations..._storyboard.Begin();对于很多同事动作的Target,我怎么知道哪个Target完成了?或者说,什么时候Stoaryboar完成了,并且其动作对应的Targe又是哪个呢?
非常感谢大家指点
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);da2 = new DoubleAnimation();
duration = new Duration(TimeSpan.FromMilliseconds(getRandomTime())); // getRandomTime()返回随机的ms时间
da2.Duration = duration;
da2.From = 1;
da2.To = 0;
da2.Completed += new EventHandler(da1_Completed);
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;
da1.Completed += new EventHandler(da1_Completed);
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;
da2.Completed += new EventHandler(da1_Completed);
rect4.BeginAnimation(Rectangle.Opacity, da2);
//在事件中判断名称就行了
void da1_Completed(object sender, EventArgs e)
{
switch (((DoubleAnimation)sender).Name)
{
case "da1":
执行的方法
break;
case "da2":
执行的方法
break;
}
}
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;
}
}