Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 有没有办法强迫故事板立即完成?_Wpf_Events_Animation_Storyboard_Code Behind - Fatal编程技术网

Wpf 有没有办法强迫故事板立即完成?

Wpf 有没有办法强迫故事板立即完成?,wpf,events,animation,storyboard,code-behind,Wpf,Events,Animation,Storyboard,Code Behind,代码的要点是 Storyboard story = new Storyboard(); DoubleAnimation anim = new DoubleAnimation(); anim.Completed += anim_Completed(object sender, EventArgs e); ... story.Children.Add(anim); story.Completed += story_Completed(object se

代码的要点是

    Storyboard story = new Storyboard();
    DoubleAnimation anim = new DoubleAnimation();
    anim.Completed += anim_Completed(object sender, EventArgs e);
    ...
    story.Children.Add(anim);
    story.Completed += story_Completed(object sender, EventArgs e);
    story.Begin(control, true);
return;
另一种方法是:

    // Finish the Storyboard now
    story.SkipToFill(control);
    // I want it to get back to me here after the Completed events have run.
问题是,完成的事件直到WPF dispatcher消息循环的下一次传递时才运行,这对我来说不好,因为它们更新了一些状态。我也试过了

    story.Stop(control);

但是,完成的处理程序似乎根本无法运行。有没有办法让已完成的处理程序立即启动?

为了避免在另一个ui线程上运行故事板并处理锁或信号,您可以尝试以下方法:

Action emptyDelegate = delegate() { };
control.Dispatcher.Invoke(DispatcherPriority.Render, emptyDelegate);
…强制执行渲染过程,从而拾取完成的事件,这些事件在UI的代码隐藏中处理期间似乎不会在需要时触发

您可能会看到一些人工制品的出现和消失,当然,任何更新的依赖属性值都会被呈现出来