Calendar.SelectedDates プロパティ

定義

選択された日付のコレクションを設定します。

public:
 property System::Windows::Controls::SelectedDatesCollection ^ SelectedDates { System::Windows::Controls::SelectedDatesCollection ^ get(); };
public System.Windows.Controls.SelectedDatesCollection SelectedDates { get; }
member this.SelectedDates : System.Windows.Controls.SelectedDatesCollection
Public ReadOnly Property SelectedDates As SelectedDatesCollection

プロパティ値

現在選択されている日付を含む SelectedDatesCollection オブジェクト。 既定値は空のコレクションです。

次の例では、複数の日付範囲が選択された を Calendar 作成します。

  // Create a Calendar that displays dates through
  // Januarary 31, 2009 and has dates that are not selectable.
  Calendar calendarWithBlackoutDates = new Calendar();
  calendarWithBlackoutDates.IsTodayHighlighted = false;
  calendarWithBlackoutDates.DisplayDate = new DateTime(2009, 1, 1);
  calendarWithBlackoutDates.DisplayDateEnd = new DateTime(2009, 1, 31);
  calendarWithBlackoutDates.SelectionMode = CalendarSelectionMode.MultipleRange;

  // Add the dates that are not selectable.
  calendarWithBlackoutDates.BlackoutDates.Add(
      new CalendarDateRange(new DateTime(2009, 1, 2), new DateTime(2009, 1, 4)));
  calendarWithBlackoutDates.BlackoutDates.Add(
      new CalendarDateRange(new DateTime(2009, 1, 9)));
  calendarWithBlackoutDates.BlackoutDates.Add(
      new CalendarDateRange(new DateTime(2009, 1, 16)));
  calendarWithBlackoutDates.BlackoutDates.Add(
      new CalendarDateRange(new DateTime(2009, 1, 23), new DateTime(2009, 1, 25)));
  calendarWithBlackoutDates.BlackoutDates.Add(
      new CalendarDateRange(new DateTime(2009, 1, 30)));

  // Add the selected dates.
  calendarWithBlackoutDates.SelectedDates.Add(
      new DateTime(2009, 1, 5));
  calendarWithBlackoutDates.SelectedDates.AddRange(
      new DateTime(2009, 1, 12), new DateTime(2009, 1, 15));
  calendarWithBlackoutDates.SelectedDates.Add(
      new DateTime(2009, 1, 27));

  // root is a Panel that is defined elswhere.
  root.Children.Add(calendarWithBlackoutDates);
' Create a Calendar that displays dates through 
' Januarary 31, 2009 and has dates that are not selectable. 
Dim calendarWithBlackoutDates As New Calendar()
calendarWithBlackoutDates.IsTodayHighlighted = False
calendarWithBlackoutDates.DisplayDate = New DateTime(2009, 1, 1)
calendarWithBlackoutDates.DisplayDateEnd = New DateTime(2009, 1, 31)
calendarWithBlackoutDates.SelectionMode = CalendarSelectionMode.MultipleRange

' Add the dates that are not selectable. 
calendarWithBlackoutDates.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 2), New DateTime(2009, 1, 4)))
calendarWithBlackoutDates.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 9)))
calendarWithBlackoutDates.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 16)))
calendarWithBlackoutDates.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 23), New DateTime(2009, 1, 25)))
calendarWithBlackoutDates.BlackoutDates.Add(New CalendarDateRange(New DateTime(2009, 1, 30)))

' Add the selected dates. 
calendarWithBlackoutDates.SelectedDates.Add(New DateTime(2009, 1, 5))
calendarWithBlackoutDates.SelectedDates.AddRange(New DateTime(2009, 1, 12), New DateTime(2009, 1, 15))
calendarWithBlackoutDates.SelectedDates.Add(New DateTime(2009, 1, 27))

' root is a Panel that is defined elswhere. 
root.Children.Add(calendarWithBlackoutDates)
<!-- Create a Calendar that displays dates through
     Januarary 31, 2009 and has dates that are not selectable. -->
<Calendar Margin="20" SelectionMode="MultipleRange"  
          IsTodayHighlighted="false" 
          DisplayDate="1/1/2009"
          DisplayDateEnd="1/31/2009"
          xmlns:sys="clr-namespace:System;assembly=mscorlib">

  <Calendar.BlackoutDates>
    <CalendarDateRange Start="1/2/2009" End="1/4/2009"/>
    <CalendarDateRange Start="1/9/2009" End="1/9/2009"/>
    <CalendarDateRange Start="1/16/2009" End="1/16/2009"/>
    <CalendarDateRange Start="1/23/2009" End="1/25/2009"/>
    <CalendarDateRange Start="1/30/2009" End="1/30/2009"/>
  </Calendar.BlackoutDates>

  <Calendar.SelectedDates>
    <sys:DateTime>1/5/2009</sys:DateTime>
    <sys:DateTime>1/12/2009</sys:DateTime>
    <sys:DateTime>1/14/2009</sys:DateTime>
    <sys:DateTime>1/13/2009</sys:DateTime>
    <sys:DateTime>1/15/2009</sys:DateTime>
    <sys:DateTime>1/27/2009</sys:DateTime>
    <sys:DateTime>4/2/2009</sys:DateTime>
  </Calendar.SelectedDates>
</Calendar>

注釈

日付は、 メソッドを使用して AddRange 個別に、または範囲内のコレクションに追加できます。 プロパティの値によっては、コレクションに SelectionMode 日付または範囲を追加するとクリアされる場合があります。 次の表に、 プロパティに与 CalendarSelectionMode える影響を SelectedDates 示します。

CalendarSelectionMode [説明]
None 選択は許可されません。 SelectedDate を設定できず、 に値を SelectedDates追加することはできません。
SingleDate を設定 SelectedDate するか、 の最初の値 SelectedDatesを使用して、1 つの日付のみを選択できます。 AddRange は使用できません。
SingleRange 1 つ日付範囲を選択できます。 を設定 SelectedDateし、 に個別に日付を SelectedDates追加するか、 を使用すると AddRange 、 から SelectedDates以前のすべての値がクリアされます。
MultipleRange 隣接していない複数の日付範囲を選択できます。 に個別に日付を追加したり、 を SelectedDates 使用 AddRange したりすると、 はクリア SelectedDatesされません。 設定 SelectedDate はクリア SelectedDatesされますが、追加の日付または範囲を追加できます。 既に選択されているか、別の範囲と重複している日付を含む範囲を追加すると、範囲の和集合が発生し、例外は発生しません。

XAML プロパティ要素の使用

<object>  
  <object.SelectedDates>  
    oneOrMoreDateTimeObjects  
  </object.SelectedDates>  
</object>  

XAML 値

oneOrMoreDateTimeObjects
1 つ以上の DateTime オブジェクト要素。

適用対象