1
votes

I'm struggling to find a solution for this. The standard wpf datepicker control has it's property BlackoutDates which disables dates in past. I want to implement this kind of functionality for Wpf xceed datetimepicker control but just don't know how? All I want to manage is to disable dates in past to be chosen when datetimepicker sets on some value. Any ideas?

2
What does the Wpf Xceed DateTimePicker have that the standard control doesn't have? You might be better off going with the standard control.Kcvin
It has time definition. In standard control there is just date.Stojdza

2 Answers

0
votes

Since BlackoutDates isn't available by default, you will have to modify the Xceed DateTimePicker. Understand how the control is composed first by reading here.

Next, notice that the DateTimePicker has a Calendar. Then observe this documentation.

From what I understand, you will need to create a Dependency Property for the control that takes some sort of collection of DateTime. In the callback of setting that porperty, you're going to want to take each item in the collection, and add that to PART_Calendar.BlackoutDates collection. FYI, since BlackoutDates is read only, you cannot make your DP be of type CalendarBlackoutDatesCollection and just set BlackoutDates in the callback; instead you need to manually add each date to the Calendar's collection.

0
votes

Without changing the actual sourcecode of the xceed toolkit (which is totally viable) and modifying the calendar portion. The next best thing would be to add a Validation rule to the textbox of the control.

public class YearValidationRule : ValidationRule 
{
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        DateTime date = value as DateTime;
        if (date == null)
            return new ValidationResult(false, "Chosen date cannot be null.");

        if(BlackoutDatesDates.Contains(date))
            return new ValidationResult(false, "This date is blacked out.");

        return ValidationResult.ValidResult;
    }
}