Introduction
TimePicker represents a control that allows a user to pick a
time value.
Step 1
Open a blank app and add TimePicker and Textblock control either from the toolbox or by copying the following XAML Code into your grid.
- <TextBlock Text=" Time Picker " FontSize="20">
- </TextBlock>
- <StackPanel Margin="20,30,0,0">
- <TimePicker Name="myTime" Header="Select a time" ClockIdentifier="12HourClock" TimeChanged="myTime_TimeChanged" Margin="15,0,0,0">
- </TimePicker>
- <TextBlock x:Name="selectedTime" Margin="15,15,0,0" Foreground="Green" />
- </StackPanel>
The Header defines a small text above the TimePicker control.
The ClockIdentifier defines whether to show a 12 hour or 24-hour clock. By default, it is a 12-hour clock. By selecting it for 24 hours the AM/PM selection part will not be available.
Step 2
Copy and paste the following code to the myTime_Time Changes event on the cs page and run your application.
- selectedTime.Text = "Selected time is " + e.NewTime.ToString();
Summary
In this article, we learned about TimePicker Control For Windows 10.