【问题标题】:in C# code (WPF project) can I raise an event at a specific point in a storyboard在 C# 代码(WPF 项目)中,我可以在情节提要的特定点引发事件吗
【发布时间】:2012-06-24 02:38:24
【问题描述】:

我有一个故事板,它可以自动反向运行 10 秒。

无论如何我可以让故事板本身沿着故事板时间线每 2 秒引发一个事件。

情节提要仅存在于 c# 代码中(不是 xaml)。

我希望这足以继续,但是,如果需要更多信息,请询问,我会解释我在做什么。

提前致谢

丹。

【问题讨论】:

    标签: c# wpf events storyboard


    【解决方案1】:

    情节提要时间线提供了一些事件,可能会有所帮助...类似于:

    private Storyboard stb = new Storyboard();
    private TimeSpan tsp = new TimeSpan();
    
    public MainWindow()
    {
        InitializeComponent();
        stb.CurrentTimeInvalidated += new EventHandler(doSomething);            
    }
    
    private void doSomething(Object sender, EventArgs e)
    {
        Clock storyboardClock = (Clock)sender;
            // or whatever other logic you want
        if (storyboardClock.CurrentTime.Value.Seconds % 2 == 0 && 
           Math.Abs((storyboardClock.CurrentTime.Value - tsp).TotalSeconds) >= 2)
        {
            // or something like this...
            tsp = storyboardClock.CurrentTime.Value
             - new TimeSpan(0,0,0,0,storyboardClock.CurrentTime.Value.Milliseconds);
            // do something
        }
    }
    

    退房:

    MSDN - CurrentTimeInvalidated

    MSDN - CurrentStateInvalidated

    【讨论】:

      猜你喜欢
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 2015-01-16
      • 2014-01-19
      • 1970-01-01
      • 2014-08-06
      相关资源
      最近更新 更多