Hi,
How can I set the time range for time selector in RadTimePicker?
User need to select time between 06:30 - 09:00 with time range 10min
Without that range, time selector looks quite messy
I tried to use DisplayDateStart and -end properties but it did not help
FrameworkElementFactory spFactory =
new
FrameworkElementFactory(
typeof
(Telerik.Windows.Controls.RadTimePicker));
spFactory.Name =
"factory"
;
spFactory.SetValue(Telerik.Windows.Controls.RadTimePicker.TimeIntervalProperty,
new
TimeSpan(0, 10, 0));
spFactory.SetValue(Telerik.Windows.Controls.RadTimePicker.DisplayDateStartProperty,
new
DateTime() +
new
TimeSpan(6, 30, 0));
spFactory.SetValue(Telerik.Windows.Controls.RadTimePicker.DisplayDateEndProperty,
new
DateTime() +
new
TimeSpan(9, 0, 0));
template.VisualTree = spFactory;
template.Seal();
Regards,
Auvo
7 Answers, 1 is accepted
In order to limit the times that could be selected with the desired interval between the time slots you need to use the StartTime and EndTime properties. By setting them to "06:30" and "09:00" the needed limitation will be achieved and the TimeInterval property should be set to "0:10:0" in order to specify the needed interval.
We hope this will help you.
Regards,
Nasko
Telerik
Nice and simply solution, it's works :)
Thank's,
Auvo
When I set the start and end time like this: StartTime="04:01" EndTime="13:59" it works as expected.
When I bind those values (see code below) and the converter return the exact same values as above 04:01 and 13:59 nothing happens and the start and end time stays at 12:00 am to 12:00 pm. Any ideas?
<telerik:RadDateTimePicker.StartTime>
<MultiBinding Converter="{StaticResource DatesToDateConverter}" ConverterParameter="startT">
<Binding Path="ActualStart"/>
<Binding Path="ActualEnd"/>
<Binding Path="Occurrence.Appointment.Status"/>
</MultiBinding>
</telerik:RadDateTimePicker.StartTime>
<telerik:RadDateTimePicker.EndTime>
<MultiBinding Converter="{StaticResource DatesToDateConverter}" ConverterParameter="endT">
<Binding Path="ActualStart"/>
<Binding Path="ActualEnd"/>
<Binding Path="Occurrence.Appointment.Status"/>
</MultiBinding>
</telerik:RadDateTimePicker.EndTime>
We are not aware of the observed by you issue. Could you please provide us some additional information about your scenario? We have noticed that you are binding also to the "Occurrence.Appointment.Status" property - is the DateTimePicker placed inside ScheduleView or inside one of the Dialogs of RadScheduleView.
Also, providing a code-snippet of the DatesToDateConverter will also be of great help for our further investigation?
We are looking forward to hearing from you.
Regards,
Nasko
Telerik by Progress
Nasko,
Yes, you are correct that the code is modifying (and inside) the Telerik.Windows.Controls.ScheduleView.xaml file. I am changing how the dialog that lets you set a start and end time for event works in the grid: (<Grid x:Name="Details" Grid.Row="2" Margin="6">)
Here is the DatesToDateConverter code:
Public Class DatesToDateConverter
Implements IMultiValueConverter
Public Function Convert(value() As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IMultiValueConverter.Convert
Dim startDate As DateTime = value(0)
Dim endDate As DateTime = value(1)
Dim status As globals.PTOStatus = [Enum].Parse(GetType(globals.PTOStatus), value(2))
Dim param As String = parameter
Select Case status
Case PTOStatus.NotSet
Return startDate.AddDays(7)
Case Else
If param = "start" Then
Return endDate
ElseIf param = "end" Then
Return startDate
ElseIf param = "startT" Then
Return "04:01" 'startDate.AddMinutes(1).ToString("HH:mm") 'allow them to scale down the request to 1 min
ElseIf param = "endT" Then
Return "13:59" 'endDate.AddMinutes(-1).ToString("HH:mm")
Else
Return startDate.AddDays(7) 'numToAdd)
End If
End Select
End Function
Public Function ConvertBack(value As Object, targetTypes() As Type, parameter As Object, culture As Globalization.CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack
Throw New NotImplementedException
End Function
End Class
Thanks so much for your help!
Andrew
Your converter returns strings when the passed parameter is "startT" or "endT". As the StartTime and EndTime properties are of type TimeSpan the return value should be TimeSpan:
Public
Function
Convert(
ByVal
values()
As
Object
,
ByVal
targetType
As
Type,
ByVal
parameter
As
Object
,
ByVal
culture
As
System.Globalization.CultureInfo)
As
Object
Implements
System.Windows.Data.IMultiValueConverter.Convert
If
parameter.ToString().Equals(
"startT"
)
Then
'Return "04:01"
Return
New
TimeSpan(4, 1, 0)
Else
'Return "13:59"
Return
New
TimeSpan(13, 59, 0)
End
If
End
Function
Could you please give it a try and let us know if it worked for you?
Hope this helps.
Regards,
Nasko
Telerik by Progress