我正在学习 c# 和 wpf。我有在 Visual Studio 2012 中运行的项目。为了更好地学习 C# 和 WPF,我正在制作一个练习应用程序,它恰好是 Simon Says 游戏。我有两个窗户。第一个窗口有一个“PLAY!” 显示下一个窗口的按钮。此窗口有 4 个按钮。我有一个整数数组,因此玩家必须按顺序按下按钮。为了向玩家显示顺序,我想按照数组中生成的顺序一个一个地为每个按钮设置动画。
这些按钮有 4 种不同的颜色,每个按钮的动画都是我用 Blend 中的 Storyboard 制作的。动画将按钮从其原始颜色变为红色,然后在两秒内返回。
动画正常工作,但所有按钮同时动画。我希望第一个按钮动画,然后当它完成时,下一个,依此类推。我将如何最好地使用 C# 和 WPF 来做到这一点。谢谢您的帮助。如果需要,我可以上传代码。
运行动画的函数
public void startbtn_Click(object sender, RoutedEventArgs e)
{
// Show the animation sequence for each button
// up until the current level. (getCurrentLevel is currently set to 5)
for (int i = 0; i <= engine.getCurrentLevel(); i++)
{
// engine.animate(i) returns the button at sequence i to animate
animate(engine.animate(i));
}
}
private void animate(int index)
{
// Storyboard for each button is in the format of ButtonAnimation_INDEX where INDEX is 1, 2, 3 or 4
Storyboard btnAnimation = (Storyboard)this.Resources["ButtonAnimation_" + index];
if (btnAnimation != null)
{
btnAnimation.Begin();
}
}