how to disable past days in calender in WPF?

You can set the DisplayDateStart property to today.

myCalendar.DisplayDateStart = DateTime.Today;

Instead of hiding all previous values, if you want to black them out, you can do this.

CalendarDateRange cdr = new CalendarDateRange(DateTime.MinValue, DateTime.Today);
myCalendar.BlackoutDates.Add(cdr);

I got the solution by trying myself.

In Window_load just add this line for calendar.

Caldate.BlackoutDates.Add(new CalendarDateRange(new DateTime(1990, 1, 1), 
DateTime.Now.AddDays(-1)));

It will block previous dates.


You have to set the DisplayDateStart attribute with Today's date

<DatePicker Name="dt_StartDateFrom" DisplayDateStart="{x:Static sys:DateTime.Today}">
</DatePicker>

Make sure you have set the

xmlns:sys="clr-namespace:System;assembly=mscorlib"

in your <UserControl> tag to be able to use the sys: parameter

P.S. To Disable future dates, you can use DisplayDateEnd attribute

Tags:

Wpf