-
-
Notifications
You must be signed in to change notification settings - Fork 39
Date Selection
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.Replacewill achieve traditional single selection. -
SelectionType.Single+SelectionAction.Modifywill achieve traditional multiple selection. -
SelectionType.Range+SelectionAction.Replacewill achieve traditional range selection.
Additionally, the calendar's SelectionDirection property can be used to control what order dates must be selected in.
For example:
-
SelectionType.Range+SelectionAction.Replace+SelectionDirection.StartToEndwill cause the range selection to only be changed by selecting the earlier, then later date. -
SelectionType.Range+SelectionAction.Replace+SelectionDirection.EndToStartwill cause the range selection to only be changed by selecting the later, then earlier date. -
SelectionType.Single+SelectionAction.Modify+SelectionDirection.Confinedwill cause the selected date to require being in between the earliest and latest selected dates. -
SelectionType.Single+SelectionAction.Modify+SelectionDirection.ConfinedReversewill cause the selected date to require being outside the earliest and latest selected dates.
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.