我假设您的控件正在使用 StoryBoard 来播放动画。StoryBoard 有一个“已完成”事件,该事件在完成运行后触发。因此,您可以执行以下操作:
public class CustomControl:Control
{
public override void ApplyTemplate()
{
_storyBoard=GetTemplateChild("AnimationStoryBoard") as Storyboard;
_storyBoard.Completed+=OnCompleted;
}
public event eventhandler AnimationCompleted;
public void Play()
{
_storyBoard.Begin();
}
private void OnCompleted(object sender, EventArgs args)
{
if(AnimationCompleted!=null)
AnimationCompleted(this,EventArg.Empty);
}
}
然后你可以做的是将你的动画链接在一起:
myCustomControl1.AnimationCompleted+=RunSecondAnimation;
myCustomControl1.Play();
private void RunSecondAnimation(object sender, EventArgs args)
{
myCustomControl2.Play();
}
现在我们可以保证动画 2 总是在动画 1 之后发生。