public partial class gamePage : PhoneApplicationPage
{
DispatcherTimer countDownTimer;
public gamePage()
{
InitializeComponent();
countDownTimer = new DispatcherTimer();
countDownTimer.Interval = new TimeSpan(0, 0, 0, 1);
countDownTimer.Tick += new EventHandler(countDownTimerEvent);
countDownTimer.Start();
txtHit.Text = "0";
txtCountdown.Text = "" + "seconds remaining";
}
int buttonCount = 0;
string stringButtonCount = "";
Random rnd = new Random();
int count = 15;
void countDownTimerEvent(object sender, EventArgs e)
{
txtCountdown.Text = count + " Seconds Remaining";
if (count > 0)
{
count--;
}
if (count == 0)
{
NavigationService.Navigate(new Uri("/highScore.xaml", UriKind.Relative));
count = 15;
buttonCount = 0;
stringButtonCount = "";
}
}
タイマーが動き続けるという事実を除いて、すべてが正常に機能しています。ページを離れた後も、タイマーはカウントを続けます。別のページに、このページに再ルーティングするコードがあります。その後、count 変数は 15 にリセットされ、カウントダウンしますが、タイマーは countDownTimer に基づいているため、15 秒全体が減ることはありません。countDownTimer.Stop() を見つけましたが、どこに配置すればよいかわかりません。ウィンドウズフォン初心者です。これが簡単な問題であることは知っていますが、理解できません。