1

Stopwatch Timer App Windows Phone

Let’s implement a very simple Stopwatch Timer app today.

We will implement following features in our Stopwatch app :

1. Show Timer

2. Pause Timer

3. Stop / Reset Timer.

UI for our App :

So basically we have StackPanel that is Vertically arranged which contains a Textbox (To Display Timer) and another Horizontally arranged StackPanel (Containing Buttons).

For Timer we have used DispatchTimer,

In StartTimer method we are setting the interval for DispatchTimer to 1 sec. So it means that a Tick event will be raised every 1 sec.

we listen to that event in ,

this.timer.Tick += timer_Tick;

Whenever the timer.tick event is raised we change the time on UI using this simple logic ,

This event is triggered every second , so increment second value every time this event is triggered.

Then check if 60 seconds, reset the seconds to zero and set minute++, similarly for minutes and hour.

And for button click events of Start, Pause , and Stop we will just call the Timer methods mentioned above in following manner :

Screen shot of Stopwatch Timer App :

timer

 

you can download the full code here : Stopwatch.

 

 

  • Bartłomiej Słowik

    I try also to get miliseconds but i dont know what i do worng.I change this.timer.Interval = new TimeSpan(0, 0, 0); to this.timer.Interval = new TimeSpan(0, 0, 0, 0, 1); and add ++this.miliseconds;
    if (this.miliseconds == 1000)
    {
    this.seconds++;
    this.miliseconds = 0;
    }


    this.StopwatchText.Text = string.Format(“{0} : {1} : {2} : {3}”, hours, minutes, seconds, miliseconds);

    But it dont work 🙁