WPF-同步动画

发布于 2024-08-20 03:35:20 字数 415 浏览 1 评论 0原文

我有这样的事情:

scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, shrinkAnimation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, shrinkAnimation);
MyDialog.Show();

动画并行正确运行(x 和 y 一起收缩),但由于 BeginAnimation 是异步调用,因此 Show() 方法在动画仍在运行(假设 shr​​inkAnimation 运行 1 秒)。

如何在调用 Show() 之前等待动画完成?

谢谢!

I have something this:

scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, shrinkAnimation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, shrinkAnimation);
MyDialog.Show();

The animations run correctly in parallel (x and y shrink together), but because BeginAnimation is an asynchronous call, the Show() method gets executed while the animation is still running (suppose shrinkAnimation runs for 1 second).

How can I wait for animations to complete before calling Show()?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2024-08-27 03:35:20

您可以使用具有已完成事件的 Storyboard 来代替 BeginAnimation 方法。这是一个设置不透明度的示例,但它是相同的概念:

DoubleAnimation animation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(1.0)));

Storyboard board = new Storyboard();
board.Children.Add(animation);

Storyboard.SetTarget(animation, MyButton);
Storyboard.SetTargetProperty(animation, new PropertyPath("(Opacity)"));

board.Completed += delegate
{
    MessageBox.Show("DONE!");
};

board.Begin();

You can use a Storyboard, which has a completed event, instead of that BeginAnimation method. Here's an example, setting opacity, but it's the same concept:

DoubleAnimation animation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(1.0)));

Storyboard board = new Storyboard();
board.Children.Add(animation);

Storyboard.SetTarget(animation, MyButton);
Storyboard.SetTargetProperty(animation, new PropertyPath("(Opacity)"));

board.Completed += delegate
{
    MessageBox.Show("DONE!");
};

board.Begin();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文