Reputation: 13302
I have a user control that handles both creating and editing an object. I'm setting a week of BlackOutDates on a DatePicker. If the date that the DatePicker's SelectedValue property is bound to falls on a blackout date, it throws an ArgumentOutOfRangeException (as is documented here: http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.selecteddate%28VS.95%29.aspx).
How do I handle this exception when it is occurring during data binding? The binding's ExceptionValidationRule only handles exceptions that occur when updating the source property. Ideally I'd like to display whatever value is already set, but have it fail validation. Like if you had a textbox with a validation rule that said it only allows the letter "a". If you bind a property set to the string "zzzzz", it's not going to blow up the application and be incapable of displaying the value, it will just fail validation.
Upvotes: 0
Views: 341
Reputation: 13302
After thinking about it, I think I'm mistakenly mixing up the concepts of blackout dates and validation. The datepicker's blackout dates are a presentational feature, not a validation mechanism. So what I've done is when the control loads, if my bound object's date occurs on a blackout date, I don't black it out. You can't have a blacked out date selected, so this is the only option. In the selected date changed event handler, I reassess the blackout dates and black them out if the selected date no longer occurs on one. So once I choose a valid date, I can't change it back to a blacked out date. Then I added an additional validation rule to make sure the control can't save if the selected date occurs on an invalid date.
Upvotes: 1