Calendar.SelectedDates Propriedade

Definição

Obtém uma coleção de datas selecionadas.

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

Valor da propriedade

Um objeto SelectedDatesCollection que contém as datas selecionadas atualmente. O padrão é uma coleção vazia.

Exemplos

O exemplo a seguir cria um Calendar que tem vários intervalos de datas selecionados.

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

Comentários

As datas podem ser adicionadas à coleção individualmente ou em um intervalo usando o AddRange método . Dependendo do valor da propriedade, adicionar SelectionMode uma data ou intervalo à coleção pode fazer com que ela seja desmarcada. A tabela a seguir lista como CalendarSelectionMode afeta a SelectedDates propriedade .

Calendarselectionmode Descrição
None Não é permitida nenhuma seleção. SelectedDate não pode ser definido e nenhum valor pode ser adicionado a SelectedDates.
SingleDate Somente uma única data pode ser selecionada, seja definindo SelectedDate ou o primeiro valor em SelectedDates. AddRange não pode ser usado.
SingleRange Um único intervalo de datas que pode ser selecionado. Definir SelectedDate, adicionar uma data individualmente a SelectedDatesou usar AddRange limpará todos os valores anteriores de SelectedDates.
MultipleRange É possível selecionar vários intervalos de datas não contíguos. Adicionar uma data individualmente a SelectedDates ou usar AddRange não limpará SelectedDates. A configuração SelectedDate ainda SelectedDateslimpará , mas datas ou intervalos adicionais podem ser adicionados. Adicionar um intervalo que inclui algumas datas que já estão selecionadas ou se sobrepõem a outro intervalo resulta na união dos intervalos e não causa uma exceção.

Uso do elemento propriedade XAML

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

Valores XAML

oneOrMoreDateTimeObjects
Um ou mais DateTime elementos de objeto.

Aplica-se a