Setting the Week Start Day
The Calendar control is aware of the current locale. By default, the first day of the week is read from the user's settings and applied to a Calendar in month mode. However, if your particular application requires a fixed day to show first, you can change this using the FirstDayOfWeek property.
The following updated XAML changes the first day of the week to be Thursday:
<Calendar Name="Cal"
DisplayDate="1999-12-31"
DisplayDateStart="1999-11-20"
DisplayDateEnd="2000-01-20"
DisplayMode="Year"
FirstDayOfWeek="Thursday"
DisplayModeChanged="Cal_DisplayModeChanged"
DisplayDateChanged="Calendar_DisplayDateChanged"
SelectedDatesChanged="Cal_SelectedDatesChanged"/>
The resultant window appears as follows:
Blackout Dates
The final property that we'll consider in this article is BlackoutDates. This property allows you to set one or more date ranges that may not be selected by the user. For example, if you were developing a hotel booking system, you may allow selection of holiday dates using a Calendar but prevent the user from choosing dates that are fully booked. The blackout dates appear crossed out in the control so that the user can see that they are unavailable.
The property holds a value of the CalendarBlackoutDatesCollection type, which is a collection of CalendarDateRange objects. Each of the objects defines start and end dates for a date range that will be unavailable for selection.
For example, the following excludes three ranges in December 1999, one of which is for a single date.
<Calendar Name="Cal"
DisplayDate="1999-12-31"
DisplayDateStart="1999-11-20"
DisplayDateEnd="2000-01-20"
DisplayModeChanged="Cal_DisplayModeChanged"
DisplayDateChanged="Calendar_DisplayDateChanged"
SelectedDatesChanged="Cal_SelectedDatesChanged">
<Calendar.BlackoutDates>
<CalendarDateRange Start="1999-12-02" End="1999-12-08"/>
<CalendarDateRange Start="1999-12-12" End="1999-12-12"/>
<CalendarDateRange Start="1999-12-25" End="1999-12-26"/>
</Calendar.BlackoutDates>
</Calendar>
Try running the program again to see the results. You should find that the blackout dates cannot be selected.
26 May 2014