Date Restrictions in .NET MAUI Calendar (SfCalendar)

14 Apr 20233 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);

Month view Minimum DateTime in .NET MAUI Calendar.

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);

Month view Maximum DateTime in .NET MAUI Calendar.

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;

Month view Enable past dates in .NET MAUI Calendar.

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;
};

Month view Selectable Day Predicate in .NET MAUI Calendar.