4 Answers, 1 is accepted
BTW, regarding my previous post, the bound data is not a null-able datatype.
Also, Is there a reason why the validation for the datepicker in general doesn't work like the validation for other controls where the user cannot lose focus until they select valid data, as opposed to clearing the field?
By design the whenever the input cannot be parsed to valid value, the SelectedDate property are set to null. However whenever the SelectedDate is bound to non nullable DateTime - it is not possible the property to be set to null that is why it is not changed.
What you can do in this scenario would be to hook to the ParseDateTimeValue event and check in the arguments whether the parsing is successful. If not you could simply revert the selected value to the previous one:
Hope this helps.
Thanks for explaining how to make the UI reflect the fact that the value hasn't changed.
Can you please address my second question of how to change the behavior so that instead of resetting the date, the user is not allowed to lose focus until he fixes the data?
One approach to make sure that there would always be a valid date selected is to implement a Data Validation of bound property. For more details you can check the following example from our online Silverlight demos (the approach is the same for WPF):
Hope this will help you to achieve the desired.