WPF storyboard的complete事件存在延迟
测试代码如下:
private void DoAnimation()
{
Storyboard st1 = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.Completed += new EventHandler(StComplete);
Storyboard.SetTargetName(da, SubCanvas.Name);
Storyboard.SetTargetProperty(da, new PropertyPath(Canvas.TopProperty));
st1.Children.Add(da);
da.From = 0;
da.To = 200;
da.Duration = TimeSpan.FromMilliseconds(2000);
da.AccelerationRatio = 1;
da.DecelerationRatio = 0;
st1.Begin(SubCanvas, HandoffBehavior.Compose, true);
}
private void StComplete(object sender, EventArgs e)
{
Thread.Sleep(1000);
}
执行后发现动画执行到结尾时还没结束就开始sleep(1000),在sleep(1000)后结束动画。
如何解决这种延迟问题?
(此时参数是正确的,但动画没有“刷新”)
或者有没有什么其他的方法能做到动画做完后执行一段代码,谢谢
------解决方案--------------------
多开个线程来做