Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Calendar.SelectedDate Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the currently selected date.

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

public Nullable<DateTime> SelectedDate { get; set; }

Property Value

Type: System.Nullable<DateTime>

The date currently selected. The default is null.

Exception Condition
ArgumentOutOfRangeException

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

-or-

The specified date is in the BlackoutDates collection.

InvalidOperationException

If set to anything other than null when SelectionMode is set to None.

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.

<Calendar SelectedDate="dateTimeString"/>

dateTimeString

A date that is in one of the formats that are listed in the DateTime XAML Syntax topic.

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. -->
<Calendar Margin="20" 
          SelectedDate="2/15/2009"
          DisplayDate="3/15/2009"
          DisplayDateStart="1/10/2009"
          DisplayDateEnd="4/18/2009"/>

.NET Framework
Available since 4.0
Silverlight
Available since 2.0
Return to top
Show:
© 2018 Microsoft