c# – 故事板完成后如何调用方法?

前端之家收集整理的这篇文章主要介绍了c# – 故事板完成后如何调用方法?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我写下面的代码
public void name(object sender,RoutedEventArgs e)
    {
        DoubleAnimation myDoubleAnimation = new DoubleAnimation();
        myDoubleAnimation.From = 1.0;
        myDoubleAnimation.To = 0.0;
        myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.2));

        sb1 = new Storyboard();
        sb1.Children.Add(myDoubleAnimation);
        Storyboard.SetTargetName(myDoubleAnimation,one.Name);
        Storyboard.SetTargetProperty(myDoubleAnimation,new PropertyPath(Grid.OpacityProperty));
        sb1.Begin(this);

        if (one.Opacity == 0)
        {
            Container_one.Children.Remove(one);
        }     
    }

但它没有正确的做法.动画工作正常,但删除错误.如何将Storyboard-End与对方法调用结合起来?

很多东西.

解决方法

由于Storyboard的执行是异步的,您需要添加“Storyboard Completed”事件处理程序:
story.Completed += new EventHandler(Story_Completed);

然后将删除代码放入:

private void Story_Completed(object sender,EventArgs e)
{
    if (one.Opacity == 0)
    {
        Container_one.Children.Remove(one);
    }
}

这将在Storyboard完成时执行.

原文链接:https://www.f2er.com/csharp/96832.html

猜你在找的C#相关文章