Calendar for Xamarin.iOS: Selection
This article describes the different selection modes available in TKCalendar
The selection mode in TKCalendar
can be altered by using the SelectionMode
property. The available options are:
-
TKCalendarSelectionMode.Node
- No selection is allowed. -
TKCalendarSelectionMode.Single
- A single date can be selected. -
TKCalendarSelectionMode.Multiple
- Different dates can be selected by tapping on them. A second tap will deselect the date. -
TKCalendarSelectionMode.Range
- A range between two dates on the same page can be selected.
Here is an example how to set the SelectionMode:
this.CalendarView.SelectionMode = TKCalendarSelectionMode.Range;
Use the SelectedDate
property to get or set the currently selected date in TKCalendar
when the single selection mode is used.
Use the SelectedDates
property to get or set the selected dates when multiple selection mode is selected.
The SelectedDatesRange
property is used to store the date range when this selection option is used.
You can determine whether a selection is changed by adopting TKCalendarDelegate
protocol:
public override void DidSelectDate (TKCalendar calendar, NSDate date)
{
Console.WriteLine (String.Format ("{0}", date));
}
You can prevent TKCalendar
from selecting specific date by handling the ShouldSelectDate
method:
public override bool ShouldSelectDate (TKCalendar calendar, NSDate date)
{
Console.WriteLine (String.Format ("Trying to select the unselectable {0}", date));
return !TKCalendar.IsDate (main.UnselectableDate, date, NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, main.CalendarView.Calendar);
}
Furthermore, the DidDeselectDate
is called when using multiple selection to notify for unselected dates:
public override void DidDeselectedDate (TKCalendar calendar, NSDate date)
{
Console.WriteLine (String.Format ("{0}", date));
}