Pasting an invalid range of dates in the RadDateRangePicker, for example, "ABC", raises an exception.
To work around this behavior, you could subscribe to the Loaded event of RadDateRangePicker and retrieve the DateRangeMaskedInput element via the visual tree helper methods. Then, subscribe to its ValueChanging event and check whether the NewValue property of the event arguments contains any letters or characters that are not valid. If it does, set the Handled property to True.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.dateRangePicker.Loaded += DateRangePicker_Loaded;
}
private void DateRangePicker_Loaded(object sender, RoutedEventArgs e)
{
DateRangeMaskedInput dateRangeMaskedInput = this.dateRangePicker.FindChildByType<DateRangeMaskedInput>();
if (dateRangeMaskedInput != null)
{
dateRangeMaskedInput.ValueChanging += DateRangeMaskedInput_ValueChanging;
}
}
private void DateRangeMaskedInput_ValueChanging(object? sender, Telerik.Windows.Controls.MaskedInput.RadMaskedInputValueChangingEventArgs e)
{
if (e.NewValue.ToString().Any(char.IsLetter))
{
e.Handled = true;
}
}
}
An ArgumentOutOfRangeException is thrown when the Separator property is set to a string that contains alpha-numeric/numeric "not required" mask tokens, and the clear button is pressed. The control works with a custom RadMaskedTextInput control to parse different date and time patterns for the start and end dates, which replaces the mask tokens with a placeholder, resulting in the exception when updating the Value property of the RadMaskedTextInput when the value is cleared.