2015-06-17 68 views
1

我正在創建一個老虎機遊戲。當我獲得勝利時,我想讓它顯示在我的TextBlock中,從0開始計數。創建我正在使用DispatcherTimer。DispatcherTimer和實時WP7

問題是,當我如整數贏= 50後,我用DispatcherTimer在我的TextBlock我看到過50,如54,56

DispatcherTimer timer = new DispatcherTimer(); 

timer.Interval = new TimeSpan(0, 0, 0, 0, 200); 
      timer.Tick += new EventHandler(Timer_Tick); 
      if (win != 0) 
      { 
       timer.Start(); 
      } 

private void Timer_Tick(object sender, EventArgs e) 
     { 
      if (timerCount == win) 
      { 
      timer.Stop(); 
      } 

     WinTextBlock.Text = timerCount.ToString(); 
     timerCount++; 

     } 

回答

1

確保timerCount在年初分配到0