I am learning c# and wpf. I have the project running in Visual Studio 2012. To learn C# and WPF better I am making a practice application which happens to be a Simon Says game. I have two windows. The first window has a “PLAY!” button that shows the next window. This window has 4 buttons. I have an array of integers so that the player has to press the buttons in order. To show the player the order, I wanted to animate each button one by one in the order that is generated in the array.
The buttons are 4 different colors and the animation for each I made from a Storyboard in Blend. The animation turns the button from its original color to red and then back over the span of two seconds.
The animation works properly however, all the buttons animate at the same time. I wanted the first button to animate, then when it is finished, the next one and so forth. How would I best do this using C# and WPF. Thanks for the help. I can upload code if needed.
The function that runs the animation
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();
}
}
I figured it out using the Completed event. I have the function now check to see if the current sequence is lower than the current level. If it is that means another button can be animated. So the completed event runs the function again with the next button to animate.