Restricting Dates from Selection

3 Sep 2020 / 3 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;
    SetContentView(sfCalendar);

    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();
    blockedDate1.Set(currentDate.Get(CalendarField.Year),
                      currentDate.Get(CalendarField.Month),
                      currentDate.Get(CalendarField.Date));
    
    for (int i = 1; i <= 5;i++)
    {
          blockedDate1.Set(currentDate.Get(CalendarField.Year),
          currentDate.Get(CalendarField.Month),
          currentDate.Get(CalendarField.Date)-10 + i);
         blackoutDateCollection.Add(blockedDate1.Time);
    }
    sfCalendar.BlackoutDates = blackoutDateCollection;
    SetContentView(sfCalendar);

    Blackout Dates support in Xamarin.Android Calendar

    NOTE

    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;
    SetContentView(calendar);