我已经创建了停止和开始按钮,但无法创建暂停/恢复按钮。有人可以给我一些关于如何处理这些方法的提示/代码吗?
PS:我的代码的另一个问题是它的计时器增加了 1000 而不是 1!有什么线索吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Threading;
namespace PhoneApp2
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
DispatcherTimer newTimer = new DispatcherTimer();
int time;
DateTime currentTime= new DateTime();
public MainPage()
{
InitializeComponent();
}
void OnTimerTick(object sender, EventArgs args)
{
long elapseTime = DateTime.Now.Ticks - currentTime.Ticks;
TimeSpan elapsedSpan = new TimeSpan(elapseTime);
textClock.Text = elapsedSpan.TotalMilliseconds.ToString("0.00");
}
private void Button_Stop(object sender, RoutedEventArgs e)
{
newTimer.Stop();
}
private void Button_Pause(object sender, RoutedEventArgs e)
{
//newTimer.Stop(); ??
}
private void Button_Start(object sender, RoutedEventArgs e)
{
currentTime = DateTime.Now;
newTimer.Interval = TimeSpan.FromSeconds(1);
newTimer.Tick += OnTimerTick;
newTimer.Start();
}
}
}