C1MonthCalendar Control
The C1MonthCalendar control is used to create a one-month calendar user interface, allowing users to select a specific date(s) interactively.
User interface abstraction of C1MonthCalendar implies an existence of three main parts:
1. A pane that represents a list of the month's days
2. A pane that represents a list of days of the week names
3. A command pane that is intended to represent a UI that manages a selection of the current month/year
A list of days is represented by the C1MonthCalendarPresenter object, which is inherited from the ListBox class. An instance of C1MonthCalendarPresenter class is used in the C1MonthCalendar's template visual tree to define a place where a panel with calendar days will appear.
C1MonthCalendar provides the following behavior regarding the day list. For the specified Year and Month properties it generates UI elements (of the DaySlotPresenter class) representing calendar day cells. An actual UI of these DaySlotPresenter elements is defined in the DaySlotTemplate property. Those elements become children of a panel whose UI is defined in the DaysPanel property. Note that a regular calendar contains 6 week rows; each row contains 7 days; therefore, 6 * 7 = 42 day cells (referred to as "slots"). Note also that some cells don't represent any day - they are just empty cells. Each DaySlotPresenter element gets a DaySlot type object as its DataContext. This allows convenient binding of the DaySlotPresenter UI to a DaySlot object. DaySlot provides information about a certain day cell, which includes the following read-only properties:
• bool Empty - indicates whether a slot represents a day or it's an empty one;
• DateTime Date - gets a date represented by the DaySlot or a null value if the DaySlot is empty;
• DayOfWeek DayOfWeek - gets the day of the week that this slot corresponds to;
• bool IsWeekEnd - indicates whether this day is a weekend;
• bool IsSelected - indicates whether this day slot is currently selected;
• bool IsAdjacent - indicates whether the DaySlot represents a day from an adjacent month, but not of the month currently represented by the C1MonthCalendar;
• bool IsBolded - indicates whether a day represented by the DaySlot is currently bolded in the C1MonthCalendar UI.
Day slots are generated with regard to culture-specific day of the week ordering. For example, if the first day of the month is a Tuesday, then the corresponding day slot will be third in the list, with two empty slots preceding it, for the USA culture, because Sunday is the first day of the week in the USA; however, it will be second in the list for the Russian culture, because Monday is the first day of the week in Russia. A represented culture is controlled by the C1MonthCalendar CalendarHelper property.
To specify a place in the calendar control UI tree (defined in the C1MonthCalendar.Template) where the abovementioned panel with days will be placed, the C1MonthCalendarPresenter type instance should be used.
Note that regardless of what panel and day representing the item UI is used, the calendar provides the ability to interactively select a day (s) using the mouse or keyboard.
The days of the week list is represented by the DaysOfWeekPresenter class derived from ItemsControl. An instance of DaysOfWeekPresenter should be used as a placeholder in the C1MonthCalendar.Template visual tree to specify where the days of the week pane should be placed. DaysOfWeekPresenter generates 7 DayOfWeekSlotPresenter objects as children of a panel whose template is defined in the C1MonthCalendar DaysOfWeekPanel. Each DayOfWeekSlotPresenter object represents a single day of the week. A UI of each DayOfWeekSlotPresenter is defined in the C1MonthCalendar DayOfWeekSlotTemplate property. Each DayOfWeekSlotPresenter receives a DayOfWeekSlot object as its DataContext. DayOfWeekSlot provides a set of properties for convenient binding of the DayOfWeekSlotPresenter UI, like:
• DayOfWeek DayOfWeek – gets the day of the week represented by the DayOfWeekSlot;
• string DayFullName – the culture-specific full name of a day;
• string DayShortName – the culture-specific abbreviated name of a day;
• string DayShortestName – the culture specific shortest name for the DayOfWeek;
• bool IsWeekEnd – indicates whether this day of the week is a weekend day.
The order of the represented days of the week in the list is culture-specific. For example, the first day of the week is Sunday in the USA culture and Monday in the Russian culture.
A command pane is represented by the CalendarCommandPanel class derived from ContentControl. It is used in the C1MonthCalendar template's visual tree to define a place where a calendar command panel will appear. The sole behavior of this class is to provide an owner C1MonthCalendar instance as a value of CalendarCommandPanel.DataContext in order to provide a convenient way to bind the command panel's UI to the calendar.
To provide a custom look for the C1MonthCalendar control:
1. To define a general layout model for a calendar, the C1MonthCalendar.Template property should be assigned; this is usually done through a Setter of a Style. The template may contain any UI elements, for example, grids with StackPanels and borders with anything, but in some area of the template tree, the following placeholder elements of the calendar should be placed:
• C1MonthCalendarPresenter - to designate a place where a days pane will appear;
• DaysOfWeekPresenter - to designate a place where a days of week pane will appear;
• CalendarCommandPanel - to designate a place where a command panel will appear,
Note that each of the placeholders enumerated above is optional.
2. To define the Days pane UI, assign templates to the following properties:
• C1MonthCalendar DaysPanel – defines a panel for the layout of day items;
• C1MonthCalendar DaySlotTemplate – defines a UI that represents each day. Bind the UI of this template using the "{Binding Path=DaySlot_Property}" markup extension, where DaySlot_Property is any property name of the DaySlot class;
• C1MonthCalendar DaySlotStyle – allows you to define the properties of a root object of the UI tree representing a separate day. This root object is of the DaySlotPresenter type.
3. To define the Days of Week pane UI, assign templates to the following properties:
• C1MonthCalendar DaysOfWeekPanel – defines a panel for the layout of days of week items;
• C1MonthCalendar DayOfWeekSlotTemplate – defines a UI that represents each day of the week. Bind the UI of this template using the "{Binding Path=DayOfWeekSlot_Property}" markup extension, where DayOfWeekSlot Property is any property of the DayOfWeekSlot class;
• C1MonthCalendar DayOfWeekSlotStyle – allows you to define the properties of a root object of the UI tree representing a separate day. This object is of the DayOfWeekSlotPresenter type.
4. To define the UI for a command panel, assign a template to the C1MonthCalendar CommandPanelTemplate property. Bind the UI of this template using the "{Binding Path=C1MonthCalendar_Property}" markup extension, where C1MonthCalendar_Property is any property of the C1MonthCalendar class.
|