Calendar.SelectedDate 屬性

定義

取得或設定目前選取的日期。

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)

屬性值

目前選取的日期。 預設為 null

例外狀況

指定的日期不在 DisplayDateStartDisplayDateEnd 所指定的範圍內

-或-

指定的日期會在 BlackoutDates 集合中。

如果在 SelectionMode 設定為 None 時,設為 null 以外的任何項目。

範例

下列範例會 Calendar 建立具有特定範圍的可顯示日期,並設定目前選取和顯示的日期。

// 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"/>

備註

相依性屬性資訊

識別碼欄位 SelectedDateProperty
設定為 的中繼資料屬性 true BindsTwoWayByDefault

當 設定為 SingleDateSelectionMode ,請使用這個屬性。 在其他模式中,這個屬性一律是 中的 SelectedDates 第一個日期。

XAML Attribute Usage

<Calendar SelectedDate="dateTimeString"/>  

XAML 值

dateTimeString
日期,其格式為 DateTime XAML 語法 主題中列出的其中一種格式。

適用於