簡體   English   中英

WPF - 同步動畫

[英]WPF - synchronous animation

我有這樣的東西:

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

動畫並行正確運行(x和y縮小在一起),但由於BeginAnimation是異步調用,因此在動畫仍在運行時執行Show()方法(假設shrinkAnimation運行1秒)。

在調用Show()之前,如何等待動畫完成?

謝謝!

您可以使用具有已完成事件的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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM