12

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);
}
4

1 回答 1

23

就在这里。

已完成的事件 (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);
}
于 2012-02-08T13:25:13.620 回答