Date Restrictions in .NET MAUI Calendar (SfCalendar)
19 Sep 20243 minutes to read
Minimum date
The MinimumDate property will restrict the backward navigation of date selection and also you cannot swipe beyond the minimum date range.
<calendar:SfCalendar x:Name="calendar"
View="Month">
</calendar:SfCalendar>
this.calendar.MinimumDate = DateTime.Now.AddDays(-5);
Maximum date
The MaximumDate property will restrict the forward navigation of date selection and also you cannot swipe beyond the maximum date range.
<calendar:SfCalendar x:Name="calendar"
View="Month">
</calendar:SfCalendar>
this.calendar.MaximumDate = DateTime.Now.AddDays(5);
Enable past dates
To enable or disable the dates before today’s date using the EnablePastDates property of the SfCalendar
and you cannot select the dates before the today date while it is disabled.
<calendar:SfCalendar x:Name="calendar"
View="Month"
EnablePastDates="false">
</calendar:SfCalendar>
this.calendar.EnablePastDates = false;
Selectable day predicate
The SelectableDayPredicate of the SfCalendar
decides whether the cell is selectable or not in calendar and if you want to disable the particular selected date in a calendar. Easily prevent the selection of weekends by disabling them. If the callback returns true, the date will be selectable in the Calendar.
<calendar:SfCalendar x:Name="calendar"
View="Month">
</calendar:SfCalendar>
this.calendar.SelectableDayPredicate = (date) =>
{
if (date.Date == DateTime.Now.AddDays(-2).Date || date.Date == DateTime.Now.AddDays(-7).Date || date.Date == DateTime.Now.AddDays(-12).Date || date.Date == DateTime.Now.AddDays(1).Date || date.Date == DateTime.Now.AddDays(15).Date)
{
return false;
}
return true;
};