It seems the year above the validation of the date picker has a problem . Anyway, now it works.
I'm not a WPF specialist, boo, I will try to give you an idea
write a validation rule
public class DateExpiredRule : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { DateTime orderDate = (DateTime)value; return new ValidationResult(orderDate < DateTime.Now, "Please, enter date before Now()"); } }
then you can attach it to datepicker
<WPFToolkit:DatePicker Name="dateProvider" Visibility="Collapsed"> </WPFToolkit:DatePicker> <WPFToolkit:DatePicker Name="notExpired"> <WPFToolkit:DatePicker.SelectedDate> <Binding ElementName="dateProvider" Path="SelectedDate" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <local:DateExpiredRule/> </Binding.ValidationRules> </Binding> </WPFToolkit:DatePicker.SelectedDate> </WPFToolkit:DatePicker>
specify the management template for validation failure. By default, a validation error changes the border color. I used an extra hint when the mouse is under control.

source
About the statement "picker for picking."
I know that you can use custom properties in validation rules (see AgeRangeRule in msdn )
Maybe you should use this feature like
<local:MaxDateRule MaxDate="{Binding ElementName=DepartureDatePicker, Path=SelectedDate" />
but in order to apply the binding, you need to make MaxDate a dependent property. You should definitely ask the guru;)
Instead of highlighting, you should consider intercepting the change in the date picker value (through some datepicker onchange event) and accept or reject the change.
jonny
source share