TimePickercontrol allows the user to pick a time value.
This example shows how to create a simple time picker with a header in XAML or in code.
TimePicker arrivalTimePicker = new TimePicker();
TimePickerto let a user enter a single time value. You can customize the
DatePickerto use a 12-hour or 24-hour clock.
By default, the time picker shows a 12-hour clock with an AM/PM selector. You can set the ClockIdentifier property to "24HourClock" to show a 24-hour clock instead.
<TimePicker Header="12HourClock" SelectedTime="14:30"/>
<TimePicker Header="24HourClock" SelectedTime="14:30" ClockIdentifier="24HourClock"/>
You can set the MinuteIncrement property to indicate the time increments shown in the minute picker. For example, 15 specifies that the
TimePickerminute control displays only the choices 00, 15, 30, 45.
The time picker control has both Time / TimeChanged and SelectedTime / SelectedTimeChanged APIs. The difference between these is that
Timeis not nullable, while
The value of
SelectedTimeis used to populate the time picker and is
nullby default. If
Timeproperty is set to a TimeSpan of 0; otherwise, the
Timevalue is synchronized with the
null, the picker is 'unset' and shows the field names instead of a time.
Initializing a time value
In code, you can initialize the time properties to a value of type
TimePicker timePicker = new TimePicker
SelectedTime = new TimeSpan(14, 15, 00) // Seconds are ignored.
You can set the time value as an attribute in XAML. This is probably easiest if you're already declaring the
TimePickerobject in XAML and aren't using bindings for the time value. Use a string in the form Hh:Mm where Hh is hours and can be between 0 and 23 and Mm is minutes and can be between 0 and 59.
To use the time value in your app, you typically use a data binding to the
Timeproperty, use the time properties directly in your code, or handle the