Prerequisites
Creating a Universal Windows app
Step 1 - Open Visual Studio 2015 and Click File ---> New ---> Project. It is the option for New Universal Windows app.
Step 2 - New Project Windows will open. Click Windows ---> Universal --->Blank app (Universal Windows) and type the name as Timer app in Name box and click OK button.
Step 3 - Setting the platform Versions
Here, we choose the Target Version, Minimum Version for our Universal Windows Application and click OK button.
Step 4 - Now, we go to Solution Explorer and open Main Page.xaml to design the page.
Step 5 - Designing the App in UWP
In Main Page.xaml designing page, drag the button control from the tool box. Go to Property Window, change the name as Startbutton and content to start Timer.
Step 6 - Next, drag the next button control from the tool box and go to the Property Window. Change the name to Stopbutton and content to stop Timer.
Step 7 - Last, drag the Textblock control from the tool box and go to the Property Window, change the name to Displaytext and content is kept as empty.
Step 8 - Add the Coding
To add the coding, double click on the Start Timer button, add the mentioned source code and type the source code.
- private void Startbutton_Click(object sender, RoutedEventArgs e)
- {
- Timmer.Start();
- }
Double click on the Stop Timer button and add the mentioned source code.
- private void Stopbutton_Click(object sender, RoutedEventArgs e)
- {
- Displaytext.Text = Timmer.Elapsed.ToString();
- string milliseconds = Timmer.ElapsedMilliseconds.ToString();
- Timmer.Stop();
- }
Add the coding, given below-
Add the header file, given below-
Finally, the coding Window looks, as given below-
Step 9 - Run the Application by clicking the Local Machine to run the Application.
Output