Итак, у меня есть две кнопки «Пуск / Стоп», и «Пуск» работает нормально, потому что он запускается в начале при каждом нажатии кнопки «Пуск», чего я и хочу.Но я новичок в формах xamarin и не совсем понимаю, как остановить device.starttimer.
Это то, что у меня сейчас, и оно не работает.(не беспокойтесь о звуке)
//timer
bool shouldRun = false;
private void timer()
{
Device.StartTimer(TimeSpan.FromSeconds(3), () =>
{
// Do something
label.Text = "Time is up!";
//shows start button instead of stop button
startButton.IsVisible = true;
//hides stop button
stopButton.IsVisible = false;
return shouldRun;
});
}
private void STOPButton_Clicked(object sender, EventArgs e)
{
//shows start button instead of stop button
startButton.IsVisible = true;
//hides stop button
stopButton.IsVisible = false;
//stops timer
shouldRun = false;
//stops sound
}
private void STARTButton_Clicked(object sender, EventArgs e)
{
//hides start button
startButton.IsVisible = false;
//shows stop button instead of start button
stopButton.IsVisible = true;
//starts timer from beginning
timer();
//starts sound from beginning
}