Restricting Dates from Selection

3 Sep 20203 minutes to read

Min Max dates

Visible dates can be restricted between certain range of dates using MinDate and MaxDate properties available in SfCalendar control. It is applicable in all the calendar views.

The inline feature in month view will work only within the min max date range.

Beyond the min max date range, following restrictions will be applied.

  • Date navigations features of MoveToDate will be restricted.
  • Cannot swipe the control using touch gesture.
  • Selection does not work for month view.
  • The tapped delegates will not be triggered while tapped on the month cell.
  • C#
  • SfCalendar sfCalendar = new SfCalendar(this);
    Calendar minCalendar = Calendar.Instance;
    minCalendar.Set(2016, 9, 1);
    Calendar maxCalendar = Calendar.Instance;
    maxCalendar.Set(2020, 9, 1);
    sfCalendar.MinDate = minCalendar;
    sfCalendar.MaxDate = maxCalendar;

    Blackout dates

    In SfCalendar, blackout dates refers the disabled dates that restrict the user from selecting it. These dates will be marked with slanted Stripes.

    The blackout dates can be achieved in two ways.

    • A date collection can be provided to set the BlackoutDates property. This is useful when one wants to block dates where holidays or any other events occur.

    • By invoking the AddDatesInPast method, all past dates will be blacked out till current date.

  • C#
  • SfCalendar sfCalendar = new SfCalendar(this);
    List<Date> blackoutDateCollection = new List<Date>();
    Calendar currentDate = Calendar.Instance;
    Calendar blockedDate1 = (Calendar)currentDate.Clone();
    for (int i = 1; i <= 5;i++)
          currentDate.Get(CalendarField.Date)-10 + i);
    sfCalendar.BlackoutDates = blackoutDateCollection;

    Blackout Dates support in Xamarin.Android Calendar


    This support is enabled only in month view and the dates that consists inline events will also be disabled, when they are blacked out.

    Customize the blackout dates Color

    You can customize the color of BlackoutDates in month view mode using the BlackOutColor property of MonthViewSettings.

    SfCalendar calendar = new SfCalendar(this); 
    MonthViewSettings monthViewSettings = new MonthViewSettings();
    monthViewSettings.BlackOutColor = Color.Red;
    calendar.MonthViewSettings = monthViewSettings;