【问题标题】:Is there any event that fires when WPF animation ends?WPF 动画结束时是否会触发任何事件?
【发布时间】:2012-02-29 22:29:18
【问题描述】:

WPF 动画结束时是否会触发任何事件?

void HideDefaultScreenImageTimer_Tick(object sender, EventArgs e)
{
    HideDefaultScreenImageTimer.Stop();

    var doubleAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.45)));
    DefaultScreenImage.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
    // I need some event when an animation ENDS and within that event I want to remove 
    // Image (DefaultScreenImage) from Canvas.
    MainCanvas.Children.Remove(DefaultScreenImage);
}

【问题讨论】:

    标签: c# wpf xaml doubleanimation


    【解决方案1】:

    是的。

    The Completed Event (MSDN).


    所以你的代码变成了:

    void HideDefaultScreenImageTimer_Tick(object sender, EventArgs e)
    {
        HideDefaultScreenImageTimer.Stop();
    
        var doubleAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.45)));
        doubleAnimation.Completed += (sender, eArgs) => MainCanvas.Children.Remove(DefaultScreenImage);
    
        DefaultScreenImage.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      相关资源
      最近更新 更多