Calendar.BlackoutDates 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取标记为不可选择的日期的集合。
public:
property System::Windows::Controls::CalendarBlackoutDatesCollection ^ BlackoutDates { System::Windows::Controls::CalendarBlackoutDatesCollection ^ get(); };
public System.Windows.Controls.CalendarBlackoutDatesCollection BlackoutDates { get; }
member this.BlackoutDates : System.Windows.Controls.CalendarBlackoutDatesCollection
Public ReadOnly Property BlackoutDates As CalendarBlackoutDatesCollection
属性值
不可选择的日期的集合。 默认值为空集合。
示例
以下示例创建一个 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>
前面的示例生成类似于下图的输出。
具有无法选择日期的日历
注解
此集合中的日期将显示为灰色,并在日历上交叉。
若要使所有过去的日期不可选择,可以使用 AddDatesInPast 此属性返回的集合提供的方法。
XAML 属性元素用法
<object>
<object.BlackoutDates>
oneOrMoreCalendarDateRanges
</object.BlackoutDates>
</object>
XAML 值
oneOrMoreCalendarDateRanges
类型的 CalendarDateRange一个或多个对象元素。