Could you please try the following code snippet,
Step:1
Add the button and textblock in xaml first.
Step:2
Use the following namespaces:
using System.Diagnostics; // for Stopwatch API Access
Step:3 use the below mentioned code snippet:
public partial class WmDevStopWatch : PhoneApplicationPage
{
Stopwatch stopWatch = new Stopwatch();
DispatcherTimer oTimer = new DispatcherTimer();
public WmDevStopWatch()
{
InitializeComponent();
oTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
oTimer.Tick += new EventHandler(TimerTick);
}
void TimerTick(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
stopWatch.Elapsed.Hours, stopWatch.Elapsed.Minutes, stopWatch.Elapsed.Seconds,
stopWatch.Elapsed.Milliseconds / 10);
textBlock1.Text = elapsedTime;
});
}
private void button1_Click(object sender, RoutedEventArgs e)
{
stopWatch.Start();
oTimer.Start();
}
}
Hope it works for you.
Let me know your feedback for the same.