I'm extending the RadDatePicker. I have implemented a new property that tells whether the text input in the DatePicker is valid (that is if can be parsed to a DateTime):
I'm setting the value of this property in an event handler for the ParseDateTimeValue event:
This seems to work fine. But the problem is that if the user deletes the text in the input the event is NOT dispatched and thus my method is not executed. If the user provides some invalid input so that my IsInputValid property is set to false and then clears the input, IsInputValid will still be false! I want to set it to true when the input is empty (this will mean that the value of the DatePicker is null which is allowed in my case).
So my question is: Is it possible to get notified in some way when the input is cleared by the user?
/// <summary>
/// Tells whether the input in the TextBox of this DatePicker is valid. This property is
/// updated continously as the user types in the TextBox.
/// </summary>
public
bool
IsInputValid
{
get
{
return
(
bool
)GetValue(RadDatePickerExtended.IsInputValidProperty);
}
set
{
SetValue(RadDatePickerExtended.IsInputValidProperty, value);
}
}
public
static
readonly
DependencyProperty IsInputValidProperty = DependencyProperty.Register(
"IsInputValid"
,
typeof
(
bool
),
typeof
(RadDatePickerExtended),
new
FrameworkPropertyMetadata(
true
));
I'm setting the value of this property in an event handler for the ParseDateTimeValue event:
private
void
RadDatePickerExtended_ParseDateTimeValue(
object
sender, ParseDateTimeEventArgs args)
{
//If RadDatePicker could not parse the input...
if
(!args.IsParsingSuccessful)
{
//HERE I DO SOME EXTRA PARSING FOR INPUT THAT I WANT TO SUPPORT
//BUT THAT IS NOT SUPPORTED BY RadDatePicker. IN ALL CASES
//WHERE THE PARSING IS SUCCESFUL AND A DATETIME IS SET, I
//ALSO SET args.IsParsingSuccessful TO TRUE.
IsInputValid = args.IsParsingSuccessful;
}
else
{
//The input was succesfully parsed by the default parsing in the RadDatePicker.
IsInputValid =
true
;
}
}
This seems to work fine. But the problem is that if the user deletes the text in the input the event is NOT dispatched and thus my method is not executed. If the user provides some invalid input so that my IsInputValid property is set to false and then clears the input, IsInputValid will still be false! I want to set it to true when the input is empty (this will mean that the value of the DatePicker is null which is allowed in my case).
So my question is: Is it possible to get notified in some way when the input is cleared by the user?