Getting Started
The RadTimePicker is a control that displays a range of times from which the user can select a single time. It essentially inherits RadDateTimePicker and sets the InputMode property to TimePicker.
Assembly References
In order to use the RadTimePicker control in your projects, you have to add references to the following assemblies:
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Input
You can find more info here.
Setting the SelectedTime
The SelectedTime property holds the selected time. Examples 1 and 2 demonstrate how you can set this property in xaml and code behind. For more information, check out the Selection article of the RadDateTimePicker.
Example 1: Setting the SelectedTime in xaml
<telerik:RadTimePicker x:Name="timePicker" SelectedTime="15:00" />
Example 2: Setting the SelectedTime in code
timePicker.SelectedTime = new TimeSpan(15,0,0);
timePicker.SelectedTime = New TimeSpan(15,0,0)
In order to take some action when the SelectedTime is changed, you can handle the SelectionChanged event. You can check out all of the available events in the Events article of the RadDateTimePicker.
StartTime, EndTime and TimeInterval
You can limit the times that can be selected by setting the StartTime and EndTime properties. The TimeInterval property allows user to specify the interval between time slots available for selection. For more information, check out the Clock Items.
Example 2: Setting the StartTime, EndTime and TimeInterval
<telerik:RadTimePicker x:Name="timePicker" TimeInterval="0:30:0" StartTime="0:0:0" EndTime="7:0:0" />
Setting the ClockItemsSource
You can also populate the RadTimePicker from code behind by setting its ClockItemsSource property to a collection of TimeSpan objects. Example 3 demonstrates how you can achieve this.
Example 3: Setting the ClockItemsSource
public DataBinding()
{
this.radTimePicker.ClockItemsSource = this.LoadDataObjects();
}
public ObservableCollection<TimeSpan> LoadDataObjects()
{
ObservableCollection<TimeSpan> times = new ObservableCollection<TimeSpan>()
{
new TimeSpan(9,0,0),
new TimeSpan(10,0,0),
new TimeSpan(10,5,0),
new TimeSpan(10,22,0),
};
return times;
}
Public Sub New()
Me.radTimePicker.ClockItemsSource = Me.LoadDataObjects()
End Sub
Public Function LoadDataObjects() As ObservableCollection(Of TimeSpan)
Dim times As New ObservableCollection(Of TimeSpan)() From {
New TimeSpan(9,0,0),
New TimeSpan(10,0,0),
New TimeSpan(10,5,0),
New TimeSpan(10,22,0)
}
Return times
End Function