Calendar.SelectedDates Property
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Gets a collection of selected dates.
Namespace: System.Windows.Controls
Assembly: System.Windows.Controls (in System.Windows.Controls.dll)
Syntax
'Declaration
Public Property SelectedDates As SelectedDatesCollection
public SelectedDatesCollection SelectedDates { get; private set; }
Property Value
Type: System.Windows.Controls.SelectedDatesCollection
A SelectedDatesCollection object that contains the currently selected dates. The default is an empty collection.
Remarks
Dates can be added to the collection either individually or in a range using the AddRange method. Depending on the value of the SelectionMode property, adding a date or range to the collection may cause it to be cleared. The following table lists how CalendarSelectionMode affects the SelectedDates property.
CalendarSelectionMode |
Description |
---|---|
No selections are allowed. SelectedDate cannot be set and no values can be added to SelectedDates. |
|
Only a single date can be selected, either by setting SelectedDate or the first value in SelectedDates. AddRange cannot be used. |
|
A single range of dates can be selected. Setting SelectedDate, adding a date individually to SelectedDates, or using AddRange will clear all previous values from SelectedDates. |
|
Multiple non-contiguous ranges of dates can be selected. Adding a date individually to SelectedDates or using AddRange will not clear SelectedDates. Setting SelectedDate will still clear SelectedDates, but additional dates or range can then be added. Adding a range that includes some dates that are already selected or overlaps with another range results in the union of the ranges and does not cause an exception. |
Examples
The following code provides an example of configuring a Calendar so that multiple ranges of dates can be selected. This example is part of a larger example available in the Calendar overview.
'Sets a Calendar to allow multiple selections, and configures
'some dates to be unselectable.
cal3.SelectionMode = CalendarSelectionMode.MultipleRange
cal3.DisplayDate = New DateTime(2009, 1, 1)
cal3.DisplayDateStart = New DateTime(2009, 1, 1)
cal3.DisplayDateEnd = New DateTime(2009, 1, 31)
cal3.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 2), New DateTime(2009, 1, 4)))
cal3.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 9)))
cal3.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 16)))
cal3.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 23), New DateTime(2009, 1, 25)))
cal3.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 30)))
cal3.SelectedDates.Add(New DateTime(2009, 1, 5))
cal3.SelectedDates.AddRange(New DateTime(2009, 1, 12), New DateTime(2009, 1, 15))
cal3.SelectedDates.Add(New DateTime(2009, 1, 27))
//Sets a Calendar to allow multiple selections, and configures
//some dates to be unselectable.
cal3.SelectionMode = CalendarSelectionMode.MultipleRange;
cal3.DisplayDate = new DateTime(2009, 1, 1);
cal3.DisplayDateStart = new DateTime(2009, 1, 1);
cal3.DisplayDateEnd = new DateTime(2009, 1, 31);
cal3.BlackoutDates.Add(new CalendarDateRange(new DateTime(2009, 1, 2), new DateTime(2009, 1, 4)));
cal3.BlackoutDates.Add(new CalendarDateRange(new DateTime(2009, 1, 9)));
cal3.BlackoutDates.Add(new CalendarDateRange(new DateTime(2009, 1, 16)));
cal3.BlackoutDates.Add(new CalendarDateRange(new DateTime(2009, 1, 23), new DateTime(2009, 1, 25)));
cal3.BlackoutDates.Add(new CalendarDateRange(new DateTime(2009, 1, 30)));
cal3.SelectedDates.Add(new DateTime(2009, 1, 5));
cal3.SelectedDates.AddRange(new DateTime(2009, 1, 12), new DateTime(2009, 1, 15));
cal3.SelectedDates.Add(new DateTime(2009, 1, 27));
Version Information
Silverlight
Supported in: 5, 4, 3
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.