【问题标题】:Is there a way to force the immediate completion of a Storyboard?有没有办法强制故事板立即完成?
【发布时间】:2015-05-31 11:24:59
【问题描述】:

代码的要点是

    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.

问题是 Completed 事件在 WPF 调度程序消息循环的下一次传递之前不会运行,这对我没有好处,因为它们会更新某些状态。我也试过了

    story.Stop(control);

但是看起来 Completed 处理程序根本没有运行。有没有办法让 Completed 处理程序立即触发?

【问题讨论】:

    标签: wpf events animation storyboard code-behind


    【解决方案1】:

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

    Action emptyDelegate = delegate() { };
    control.Dispatcher.Invoke(DispatcherPriority.Render, emptyDelegate);
    

    ...强制渲染通道,从而在 UI 的代码隐藏处理过程中获取在您需要时似乎不会触发的已完成事件。

    您可能会看到一些人工制品的出现和消失,因为任何更新的依赖属性值当然会被渲染。

    【讨论】:

      猜你喜欢
      • 2010-11-04
      • 2011-03-29
      • 2016-05-09
      • 2019-12-24
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多