简体   繁体   English

等待动画完成再恢复

[英]wait for animation to finish before resuming

i am animating a line using this function 我正在使用此功能为线设置动画

 public static void Line(Canvas Drawing_Area, Point p1, Point p2)
    {
        Line line = new Line();
        Drawing_Area.Children.Insert(0, line);
        line.Stroke = Brushes.Black;
        line.StrokeThickness = 3;
        Storyboard sb = new Storyboard();
        Random r = new Random();
        line.X1 = p1.X;
        line.Y1 = p1.Y - TopMargin;
        line.X2 = p1.X;
        line.Y2 = p1.Y - TopMargin;
        DoubleAnimation animation1 = new DoubleAnimation(line.Y1, p1.Y - TopMargin, new Duration(new TimeSpan(0, 0, 1)));
        DoubleAnimation animation2 = new DoubleAnimation(line.X1, p1.X, new Duration(new TimeSpan(0, 0, 1)));
        DoubleAnimation animation3 = new DoubleAnimation(line.Y2, p2.Y - TopMargin, new Duration(new TimeSpan(0, 0, 1)));
        DoubleAnimation animation4 = new DoubleAnimation(line.X2, p2.X, new Duration(new TimeSpan(0, 0, 1)));
        Storyboard.SetTargetProperty(animation1, new PropertyPath("(Line.Y1)"));
        Storyboard.SetTargetProperty(animation2, new PropertyPath("(Line.X1)"));
        Storyboard.SetTargetProperty(animation3, new PropertyPath("(Line.Y2)"));
        Storyboard.SetTargetProperty(animation4, new PropertyPath("(Line.X2)"));
        sb.Children.Add(animation1);
        sb.Children.Add(animation2);
        sb.Children.Add(animation3);
        sb.Children.Add(animation4);
        sb.Begin(line);
    }

how can i wait for the animation to finish before continuing (existing the function) 我如何等待动画完成再继续(现有功能)

Storyboard has a Completed event which you could subscribe to that tells you when the storyboard has finished running. 故事板有一个Completed事件,您可以订阅事件,告诉您故事板何时完成运行。

You could also use Event Wait Handles to block the thread from continuing execution until your other event fires. 您还可以使用事件等待句柄来阻止线程继续执行,直到触发其他事件为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM