Freigeben über


Calendar.SelectedDate Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the currently selected date.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)

Syntax

'Declaration
<TypeConverterAttribute(GetType(DateTimeTypeConverter))> _
Public Property SelectedDate As Nullable(Of DateTime)
[TypeConverterAttribute(typeof(DateTimeTypeConverter))]
public Nullable<DateTime> SelectedDate { get; set; }
<sdk:Calendar SelectedDate="dateTimeString"/>

XAML Values

  • dateTimeString
    A date specified in the format yyyy/mm/dd. The mm and dd components must always consist of two characters, with a leading zero if necessary. For instance, the month of May should be specified as 05.

Property Value

Type: System.Nullable<DateTime>
The date currently selected. The default is nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
ArgumentOutOfRangeException

The given date is outside the range specified by DisplayDateStart and DisplayDateEnd

-or-

The given date is in the BlackoutDates collection.

InvalidOperationException

If set to anything other than nulla null reference (Nothing in Visual Basic) when SelectionMode is set to None.

Remarks

Dependency property identifier field: SelectedDateProperty

Use this property when SelectionMode is set to SingleDate. In other modes, this property will always be the first date in SelectedDates.

Examples

The following code sets up a Calendar with a particular range of displayable dates, and sets the currently selected and displayed date. This example is part of a larger example available in the Calendar overview.

' Sets a Calendar to display a range of dates from 1/10/2009 to 
' 4/18/2009. 2/15/2009 is selected, but 3/2009 is initially 
' displayed. 
cal.SelectedDate = New DateTime(2009, 2, 15)
cal.DisplayDate = New DateTime(2009, 3, 15)

' if DisplayDate is not set, the Calendar displays 
' the SelectedDate. 
cal.DisplayDateStart = New DateTime(2009, 1, 10)
cal.DisplayDateEnd = New DateTime(2009, 4, 18)
//Sets a Calendar to display a range of dates from 1/10/2009 to 
//4/18/2009.  2/15/2009 is selected, but 3/2009 is initially 
//displayed.
cal.SelectedDate = new DateTime(2009, 2, 15);
cal.DisplayDate = new DateTime(2009, 3, 15); //if DisplayDate is not set, the Calendar displays
//the SelectedDate.
cal.DisplayDateStart = new DateTime(2009, 1, 10);
cal.DisplayDateEnd = new DateTime(2009, 4, 18);

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.