Skip to content

Date Selection

Marvin E edited this page Apr 21, 2024 · 28 revisions

Calendar

Selection can be performed by changing/modifying the SelectedDates collection.

Alternatively, selection can be performed by calling the ChangeDateSelection method.

Selection can also be performed by setting the RangeSelectionStart and RangeSelectionEnd properties to non-null values. If they are both not null, CommitRangeSelection will be called and they will be set back to null. This mimicks what the ChangeDateSelection method does when the Calendar's SelectionType property is set to SelectionType.Range.

The way in which dates are selected can be changed by setting the Calendar's SelectionType property.

The action taken when calling the ChangeDateSelection or CommitRangeSelection methods can be changed by setting the SelectionAction property.

Different combinations of the SelectionType and SelectionAction result in different behaviours when calling the ChangeDateSelection method.

For example:

  • SelectionType.Single + SelectionAction.Replace will achieve traditional single selection.
  • SelectionType.Single + SelectionAction.Modify will achieve traditional multiple selection.
  • SelectionType.Range + SelectionAction.Replace will achieve traditional range selection.

CalendarView

The CalendarView does not implement selection by default. The easiest way to implement this is to set the CalendarView's DayTemplate to a DayView and set its CurrentMonthCommand, TodayComand, and SelectedCommand to a command that will select the underlying ICalendarDay's date.

To make it easier to replicate default behaviour of calendar days, there is a default style for each state of the DayView in the XCalendar.[Forms/Maui].Styles.DefaultStyles namespace which can be used via a namespace reference in XAML and the {x:Static } markup extension. These styles can also be inherited from to easily customise the look and behaviour of a day in a specific state.