How to disable manual input in a Telerik RadDatePicker

4.7k views Asked by At

I am using a Telerik RadDatePicker, and I want to disable input by the user, but they should be able to select from the calender.

<telerik:RadDatePicker Culture="{Binding GetLanguage}" x:Name="startDate" 
                       Margin="0,5,0,5" HorizontalAlignment="Left"
                       VerticalAlignment="Center" Grid.Column="1" TabIndex="2"
                       MinWidth="120" Width="120" Height="Auto" MaxHeight="25"
                       KeyDown="filterDate_KeyDown" >
</telerik:RadDatePicker>

I have used KeyDown but it did not help.

5

There are 5 answers

0
Sourabh On BEST ANSWER

The PreviewKeyDown event exists exactly for this sort of thing.

private void spacebarHandler_PreviewKeyDown(object sender, KeyEventArgs e)
 {
if (e.Key == Key.Space)
    e.Handled = true;
}
0
Gürbüz Özdemir On

Set the IsHitTestVisible=False, problem solved.

    <telerik:RadDatePicker                          
    SelectedDate="{Binding ValidFrom,Mode=TwoWay}" >
                <telerik:RadDatePicker.Resources>
                    <Style TargetType="telerik:RadWatermarkTextBox">
                        <Setter Property="IsHitTestVisible" Value="False" />                          
                    </Style>
                </telerik:RadDatePicker.Resources>

0
Michael Gilreath On

There is a property DateInput-ReadOnly. Set it to true and you should be good to go.

1
Grant Winney On

Subscribe to the KeyDown event:

<telerik:RadDatePicker KeyDown="StartDate_OnKeyDown" />

And then "handle" all keys, which effectively disables the user from typing anything:

private void StartDate_OnKeyDown(object sender, KeyEventArgs e)
{
    e.Handled = true;
}

Interestingly, there's an IsReadOnly property on the RadDatePicker, which disables the DatePickerTextBox and still allows the user to view the calendar, but unfortunately it also prevents the user from actually making a selection in the calendar. It makes it look like you can select a date, but then it doesn't actually set the SelectedDate property.

0
Maria Mathew On

There is an easy solution to this problem.

Adding the property EnableTyping="false" prevents the user from typing.

<telerik:RadDatePicker runat="server" ID="rdpPreviousDay" EnableTyping="false"></telerik:RadDatePicker>