I have an event that runs when a button is pressed:
private void AnswerPressAction(object sender, RoutedEventArgs e) { Button button = (Button)sender; Button validButton = null; string buttonName = button.Name; button.Background = new SolidColorBrush(Colors.Yellow); System.Threading.Thread.Sleep(1000); int presedAnswer = 0; switch (buttonName) { case "buttonAnswer1": presedAnswer = 1; break; case "buttonAnswer2": presedAnswer = 2; break; case "buttonAnswer3": presedAnswer = 3; break; case "buttonAnswer4": presedAnswer = 4; break; } switch (_valid_answer) { case 1: validButton = buttonAnswer1; break; case 2: validButton = buttonAnswer2; break; case 3: validButton = buttonAnswer3; break; case 4: validButton = buttonAnswer4; break; } if (presedAnswer != 0 && presedAnswer == _valid_answer) { button.Background = new SolidColorBrush(Colors.Green); System.Threading.Thread.Sleep(1000); _gameLevel++; CreateQuestion(_gameLevel); } else { button.Background = new SolidColorBrush(Colors.Red); validButton.Background = new SolidColorBrush(Colors.Green); System.Threading.Thread.Sleep(1000); MainPage mp = new MainPage(); NavigationService.Navigate(new Uri("/MainPage.xaml?show_error=true", UriKind.Relative)); _gameLevel = 0; } } The problem is that I cannot set the button color to the desired one at the event, because while the event is running, the button is "pressed", and I need to manipulate the button during the method.
Can you please tell me if there is a way to transfer control to another method, so that the button is no longer pressed, i.e. at the end of the event.
Normal- Dmitry