Calendar.SelectedDate Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the currently selected date.
public:
property Nullable<DateTime> SelectedDate { Nullable<DateTime> get(); void set(Nullable<DateTime> value); };
public DateTime? SelectedDate { get; set; }
member this.SelectedDate : Nullable<DateTime> with get, set
Public Property SelectedDate As Nullable(Of DateTime)
Property Value
The date currently selected. The default is null
.
Exceptions
The specified date is outside the range specified by DisplayDateStart and DisplayDateEnd
-or-
The specified date is in the BlackoutDates collection.
If set to anything other than null
when SelectionMode is set to None.
Examples
The following example creates a Calendar with a particular range of displayable dates, and sets the currently selected and displayed date.
// Create a Calendar that displays 1/10/2009
// through 4/18/2009.
Calendar basicCalendar = new Calendar();
basicCalendar.DisplayDateStart = new DateTime(2009, 1, 10);
basicCalendar.DisplayDateEnd = new DateTime(2009, 4, 18);
basicCalendar.DisplayDate = new DateTime(2009, 3, 15);
basicCalendar.SelectedDate = new DateTime(2009, 2, 15);
// root is a Panel that is defined elswhere.
root.Children.Add(basicCalendar);
' Create a Calendar that displays 1/10/2009
' through 4/18/2009.
Dim basicCalendar As New Calendar()
basicCalendar.DisplayDateStart = New DateTime(2009, 1, 10)
basicCalendar.DisplayDateEnd = New DateTime(2009, 4, 18)
basicCalendar.DisplayDate = New DateTime(2009, 3, 15)
basicCalendar.SelectedDate = New DateTime(2009, 2, 15)
' root is a Panel that is defined elswhere.
root.Children.Add(basicCalendar)
<!-- Create a Calendar that displays 1/10/2009
through 4/18/2009. -->
<Calendar Margin="20"
SelectedDate="2/15/2009"
DisplayDate="3/15/2009"
DisplayDateStart="1/10/2009"
DisplayDateEnd="4/18/2009"/>
Remarks
Dependency Property Information
Item | Value |
---|---|
Identifier field | SelectedDateProperty |
Metadata properties set to true |
BindsTwoWayByDefault |
Use this property when SelectionMode is set to SingleDate. In other modes, this property will always be the first date in SelectedDates.
XAML Attribute Usage
<Calendar SelectedDate="dateTimeString"/>
XAML Values
dateTimeString A date that is in one of the formats that are listed in the DateTime XAML Syntax topic.