I'm trying to write an alarm clock app for Windows Phone that requires the user to solve a math problem upon the ringing of the alarm. Right now I'm stuck, I've got the MainPage containing the settings for turning on the alarm, and when the alarm rings the user is redirected to another xaml page, one that requires the user to enter the answer to a randomly generated math problem in order to turn off the alarm. My problem is, once the user solves the problem and taps the check box, the app is supposed to first set the alarmSet value to false, and redirect the user back to the mainPage:
private void Solve_Click(object sender, EventArgs e)
{
this.userSolve = Convert.ToInt32(answerInput.Text);
if (userSolve != answer)
{
MessageBox.Show("Incorrect");
//userAnswerInt = Convert.ToInt32(answerInput.Text);
}
else if (userSolve == answer)
{
MainPage.alarmSet.Value = false;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
And then when the user arrives at the mainPage, the OnLoaded method is supposed to stop the alarm sound and reset everything back to normal:
public async void OnLoaded(object sender, EventArgs e)
{
this.timer.Stop();
this.alarmSound.Stop();
alarmSet.Value = false;
this.notificationSwitch.IsChecked = alarmSet.Value;
this.timePicker.Value = new DateTime(1, 1, 1,
alarmTime.Value.Hours,
alarmTime.Value.Minutes,
0
);
if (alarmSet.Value == true)
this.alarmTimeText.Text = alarmTimeString;
else if (alarmSet.Value == false)
this.alarmTimeText.Text = "alarm off";
But the problem is, every time the user solves the math problem, they're taken back to the main page and immediately redirected back to the alarm ringing page, because the alarm is still turned on. This creates an infinite loop of alarms overlapping each other, and I can't figure out why, even though I set alarmSet.Value to false before navigating back to the main page, the alarm is still seen as on... is there something more I need to be doing? How can I have the alarm on and set to the current minute the clock is at without it ringing immediately?