In This Article

MonthCalendar Class

Represents a month calendar control.

public class MonthCalendar : Control
Inheritance:
object Visual UIElement FrameworkElement Control object

Constructors

MonthCalendar()

Initializes an instance of the class.

public MonthCalendar()

Properties

ActiveDate

The active date in the calendar.

public DateTime ActiveDate { get; set; }

Property Value

DateTime

ActiveViewMode

The active view mode of the calendar.

public MonthCalendarViewMode ActiveViewMode { get; set; }

Property Value

MonthCalendarViewMode:

The default value is Month.

CalendarWeekRule

The calendar week rule, which determines how weeks are numbered.

public CalendarWeekRule? CalendarWeekRule { get; set; }

Property Value

CalendarWeekRule?:

When set to null, the calendar week rule is pulled from the current culture. The default value is null.

CanRetainTime

Indicates whether the various DateTime values can retain the time-portion, or if it is reset to midnight.

public bool CanRetainTime { get; set; }

Property Value

bool:

true if the various DateTime values can retain the time-portion; otherwise, false. The default value is false.

ClearButtonStyle

The Style to apply to the Clear button.

public Style? ClearButtonStyle { get; set; }

Property Value

Style

ClearButtonText

The text to display in the Clear button.

public string ClearButtonText { get; set; }

Property Value

string

ClearSelectionCommand

The ICommand that is used to clear the selection.

public ICommand ClearSelectionCommand { get; }

Property Value

ICommand

DayItemTemplate

The DataTemplate to use for day items.

public DataTemplate? DayItemTemplate { get; set; }

Property Value

DataTemplate

DayItemTemplateSelector

The DataTemplateSelector to use for day items.

public DataTemplateSelector? DayItemTemplateSelector { get; set; }

Property Value

DataTemplateSelector

DayItemsPanelTemplate

The ItemsPanelTemplate to use for arranging day items.

public ItemsPanelTemplate? DayItemsPanelTemplate { get; set; }

Property Value

ItemsPanelTemplate

DayNameItemContainerStyle

The Style to apply to day name items.

public Style? DayNameItemContainerStyle { get; set; }

Property Value

Style

DayNameItemTemplate

The DataTemplate to use for day name items.

public DataTemplate? DayNameItemTemplate { get; set; }

Property Value

DataTemplate

DayNameItemsPanelTemplate

The ItemsPanelTemplate to use for arranging day name items.

public ItemsPanelTemplate? DayNameItemsPanelTemplate { get; set; }

Property Value

ItemsPanelTemplate

DayOfWeekFormatPattern

The format pattern used for DayOfWeek values.

public DayOfWeekFormatPattern DayOfWeekFormatPattern { get; set; }

Property Value

DayOfWeekFormatPattern:

The default value is AbbreviatedUppercase.

DecadeItemTemplate

The DataTemplate to use for decade items.

public DataTemplate? DecadeItemTemplate { get; set; }

Property Value

DataTemplate

DecadeItemsPanelTemplate

The ItemsPanelTemplate to use for arranging decade items.

public ItemsPanelTemplate? DecadeItemsPanelTemplate { get; set; }

Property Value

ItemsPanelTemplate

DisabledDaysOfWeek

The disabled days of the week.

public DaysOfWeek DisabledDaysOfWeek { get; set; }

Property Value

DaysOfWeek:

The default value is None.

FirstDayOfWeek

The first day of the week.

public DayOfWeek? FirstDayOfWeek { get; set; }

Property Value

DayOfWeek?:

When set to null, the first day of the week is pulled from the current culture. The default value is null.

GoToNextViewCommand

The ICommand that is used to go to the next view.

public ICommand GoToNextViewCommand { get; }

Property Value

ICommand

GoToPreviousViewCommand

The ICommand that is used to go to the next view.

public ICommand GoToPreviousViewCommand { get; }

Property Value

ICommand

IsClearButtonVisible

Indicates whether the clear button is visible.

public bool IsClearButtonVisible { get; set; }

Property Value

bool:

true if the clear button is visible; otherwise false. The default value is false.

IsDateDisabledFunc

A function that is called when a day cell is rendered to determine if it should be disabled.

public Func<DateTime, bool>? IsDateDisabledFunc { get; set; }

Property Value

Func<DateTime, bool>

Remarks

This function is not called for dates that are outside of the Minimum and Maximum range, nor for dates that are disabled by the DisabledDaysOfWeek property.

IsDayOfWeekSelectionEnabled

Indicates whether the day of week headers can be used to select dates.

public bool IsDayOfWeekSelectionEnabled { get; set; }

Property Value

bool:

true if the day of week headers can be used to select dates; otherwise false. The default value is true.

IsTodayButtonVisible

Indicates whether the Today button is visible.

public bool IsTodayButtonVisible { get; set; }

Property Value

bool:

true if the Today button is visible; otherwise false. The default value is true.

IsTodayHighlighted

Indicates whether DateTime.Today is highlighted.

public bool IsTodayHighlighted { get; set; }

Property Value

bool:

true if DateTime.Today is highlighted; otherwise false. The default value is true.

IsWeekNumberColumnVisible

Indicates whether the week number column is visible.

public bool IsWeekNumberColumnVisible { get; set; }

Property Value

bool:

true if the week number column is visible; otherwise false. The default value is false.

IsWeekNumberSelectionEnabled

Indicates whether the week numbers can be used to select dates.

public bool IsWeekNumberSelectionEnabled { get; set; }

Property Value

bool:

true if the week numbers can be used to select dates; otherwise false. The default value is true.

MaxSelectionCount

The maximum number of dates that can be selected.

public int MaxSelectionCount { get; set; }

Property Value

int:

The default value is -1, which indicates no upper limit.

MaxViewMode

The maximum view mode allowed.

public MonthCalendarViewMode MaxViewMode { get; set; }

Property Value

MonthCalendarViewMode:

The default value is Century.

See Also

Maximum

The highest possible value.

public DateTime Maximum { get; set; }

Property Value

DateTime

Minimum

The lowest possible value.

public DateTime Minimum { get; set; }

Property Value

DateTime

MonthItemTemplate

The DataTemplate to use for month items.

public DataTemplate? MonthItemTemplate { get; set; }

Property Value

DataTemplate

MonthItemsPanelTemplate

The ItemsPanelTemplate to use for arranging month items.

public ItemsPanelTemplate? MonthItemsPanelTemplate { get; set; }

Property Value

ItemsPanelTemplate

NavigationButtonStyle

The Style to apply to the navigation buttons.

public Style? NavigationButtonStyle { get; set; }

Property Value

Style

SelectDateCommand

The ICommand that is used to select a date.

public ICommand SelectDateCommand { get; }

Property Value

ICommand

SelectDayOfWeekCommand

The ICommand that is used to select an entire day of week.

public ICommand SelectDayOfWeekCommand { get; }

Property Value

ICommand

SelectTodayCommand

The ICommand that is used to select today's date.

public ICommand SelectTodayCommand { get; }

Property Value

ICommand

Remarks

This command calls the SelectToday() method.

SelectWeekCommand

The ICommand that is used to select an entire week.

public ICommand SelectWeekCommand { get; }

Property Value

ICommand

SelectedDate

The selected date, if any, in the calendar.

public DateTime? SelectedDate { get; set; }

Property Value

DateTime?

SelectedDates

The currently-selected dates in the calendar.

public DateRangeCollection SelectedDates { get; }

Property Value

DateRangeCollection

SelectionMode

The selection mode of the calendar.

public MonthCalendarSelectionMode SelectionMode { get; set; }

Property Value

MonthCalendarSelectionMode:

The default value is Single.

Title

The title that is displayed for the active view.

public string? Title { get; }

Property Value

string

TitleButtonStyle

The Style to apply to the title button.

public Style? TitleButtonStyle { get; set; }

Property Value

Style

TodayButtonStyle

The Style to apply to the Today button.

public Style? TodayButtonStyle { get; set; }

Property Value

Style

TodayButtonText

The text to display in the Today button.

public string TodayButtonText { get; }

Property Value

string

ViewResetMode

The view reset mode, which can be used to reset the view when the calendar loses focus.

public MonthCalendarViewResetMode ViewResetMode { get; set; }

Property Value

MonthCalendarViewResetMode:

The default value is None.

WeekNumberItemContainerStyle

The Style to apply to week number items.

public Style? WeekNumberItemContainerStyle { get; set; }

Property Value

Style

WeekNumberItemTemplate

The DataTemplate to use for week number items.

public DataTemplate? WeekNumberItemTemplate { get; set; }

Property Value

DataTemplate

WeekNumberItemsPanelTemplate

The ItemsPanelTemplate to use for arranging week number items.

public ItemsPanelTemplate? WeekNumberItemsPanelTemplate { get; set; }

Property Value

ItemsPanelTemplate

YearItemTemplate

The DataTemplate to use for year items.

public DataTemplate? YearItemTemplate { get; set; }

Property Value

DataTemplate

YearItemsPanelTemplate

The ItemsPanelTemplate to use for arranging year items.

public ItemsPanelTemplate? YearItemsPanelTemplate { get; set; }

Property Value

ItemsPanelTemplate

ZoomInCommand

The ICommand that is used to zoom in.

public ICommand ZoomInCommand { get; }

Property Value

ICommand

ZoomOutCommand

The ICommand that is used to zoom out.

public ICommand ZoomOutCommand { get; }

Property Value

ICommand

Methods

OnApplyTemplate()

Invoked whenever application code or internal processes call ApplyTemplate.

public override void OnApplyTemplate()

OnCreateAutomationPeer()

Returns class-specific AutomationPeer implementations for the Windows Presentation Foundation (WPF) infrastructure.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer:

The type-specific AutomationPeer implementation.

OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs)

Invoked just before the IsKeyboardFocusWithinChanged event is raised by this element. Implement this method to add class handling for this event.

protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
Parameter Type Description
e DependencyPropertyChangedEventArgs

A System.Windows.DependencyPropertyChangedEventArgs that contains the event data.

OnKeyDown(KeyEventArgs)

Invoked when an unhandled System.Windows.Input.Keyboard.KeyDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

protected override void OnKeyDown(KeyEventArgs e)
Parameter Type Description
e KeyEventArgs

The KeyEventArgs that contains the event data.

Refresh(bool)

Refreshes the control.

public void Refresh(bool requiresNewView)
Parameter Type Description
requiresNewView bool

Whether a new view is required (if UI elements are changing instead of only simple data).

SelectToday()

Selects today's date.

public void SelectToday()

UpdateDayItem(MonthCalendarItem, DateTime)

Updates a MonthCalendarItem for the specified day.

protected virtual void UpdateDayItem(MonthCalendarItem item, DateTime date)
Parameter Type Description
item MonthCalendarItem

The MonthCalendarItem to update.

date DateTime

The date for which to update the model.

UpdateDayNameItem(MonthCalendarItem, DayOfWeek)

Updates a MonthCalendarItem for the specified day of week.

protected virtual void UpdateDayNameItem(MonthCalendarItem item, DayOfWeek dayOfWeek)
Parameter Type Description
item MonthCalendarItem

The MonthCalendarItem to update.

dayOfWeek DayOfWeek

The updated day of week.

UpdateDecadeItem(MonthCalendarItem, DateTime)

Updates a MonthCalendarItem for the specified decade.

protected virtual void UpdateDecadeItem(MonthCalendarItem item, DateTime date)
Parameter Type Description
item MonthCalendarItem

The MonthCalendarItem to update.

date DateTime

The date for which to update the model.

UpdateMonthItem(MonthCalendarItem, DateTime)

Updates a MonthCalendarItem for the specified month.

protected virtual void UpdateMonthItem(MonthCalendarItem item, DateTime date)
Parameter Type Description
item MonthCalendarItem

The MonthCalendarItem to update.

date DateTime

The date for which to update the model.

UpdateWeekNumberItem(MonthCalendarItem, int)

Updates a MonthCalendarItem for the specified week number.

protected virtual void UpdateWeekNumberItem(MonthCalendarItem item, int weekNumber)
Parameter Type Description
item MonthCalendarItem

The MonthCalendarItem to update.

weekNumber int

The updated week number.

UpdateYearItem(MonthCalendarItem, DateTime)

Updates a MonthCalendarItem for the specified year.

protected virtual void UpdateYearItem(MonthCalendarItem item, DateTime date)
Parameter Type Description
item MonthCalendarItem

The MonthCalendarItem to update.

date DateTime

The date for which to update the model.

Events

SelectionChanged

Occurs after the SelectedDate property value and/or SelectedDates collection changes.

public event EventHandler? SelectionChanged

Event Type

EventHandler

SelectionCommitted

Occurs when the selection is committed, either by pressing Enter or clicking on a date value in single selection mode.

public event EventHandler? SelectionCommitted

Event Type

EventHandler

Fields

ActiveDateProperty

Defines the ActiveDate property.

public static readonly DependencyProperty ActiveDateProperty

ActiveViewModeProperty

Defines the ActiveViewMode property.

public static readonly DependencyProperty ActiveViewModeProperty

CalendarWeekRuleProperty

Defines the CalendarWeekRule property.

public static readonly DependencyProperty CalendarWeekRuleProperty

CanRetainTimeProperty

Defines the CanRetainTime property.

public static readonly DependencyProperty CanRetainTimeProperty

ClearButtonStyleProperty

Defines the ClearButtonStyle property.

public static readonly DependencyProperty ClearButtonStyleProperty

ClearButtonTextProperty

Defines the ClearButtonText property.

public static readonly DependencyProperty ClearButtonTextProperty

DayItemTemplateProperty

Defines the DayItemTemplate property.

public static readonly DependencyProperty DayItemTemplateProperty

DayItemTemplateSelectorProperty

Defines the DayItemTemplateSelector property.

public static readonly DependencyProperty DayItemTemplateSelectorProperty

DayItemsPanelTemplateProperty

Defines the DayItemsPanelTemplate property.

public static readonly DependencyProperty DayItemsPanelTemplateProperty

DayNameItemContainerStyleProperty

Defines the DayNameItemContainerStyle property.

public static readonly DependencyProperty DayNameItemContainerStyleProperty

DayNameItemTemplateProperty

Defines the DayNameItemTemplate property.

public static readonly DependencyProperty DayNameItemTemplateProperty

DayNameItemsPanelTemplateProperty

Defines the DayNameItemsPanelTemplate property.

public static readonly DependencyProperty DayNameItemsPanelTemplateProperty

DayOfWeekFormatPatternProperty

Defines the DayOfWeekFormatPattern property.

public static readonly DependencyProperty DayOfWeekFormatPatternProperty

DecadeItemTemplateProperty

Defines the DecadeItemTemplate property.

public static readonly DependencyProperty DecadeItemTemplateProperty

DecadeItemsPanelTemplateProperty

Defines the DecadeItemsPanelTemplate property.

public static readonly DependencyProperty DecadeItemsPanelTemplateProperty

DisabledDaysOfWeekProperty

Defines the DisabledDaysOfWeek property.

public static readonly DependencyProperty DisabledDaysOfWeekProperty

FirstDayOfWeekProperty

Defines the FirstDayOfWeek property.

public static readonly DependencyProperty FirstDayOfWeekProperty

IsClearButtonVisibleProperty

Defines the IsClearButtonVisible property.

public static readonly DependencyProperty IsClearButtonVisibleProperty

IsDateDisabledFuncProperty

Defines the IsDateDisabledFunc property.

public static readonly DependencyProperty IsDateDisabledFuncProperty

IsDayOfWeekSelectionEnabledProperty

Defines the IsDayOfWeekSelectionEnabled property.

public static readonly DependencyProperty IsDayOfWeekSelectionEnabledProperty

IsTodayButtonVisibleProperty

Defines the IsTodayButtonVisible property.

public static readonly DependencyProperty IsTodayButtonVisibleProperty

IsTodayHighlightedProperty

Defines the IsTodayHighlighted property.

public static readonly DependencyProperty IsTodayHighlightedProperty

IsWeekNumberColumnVisibleProperty

Defines the IsWeekNumberColumnVisible property.

public static readonly DependencyProperty IsWeekNumberColumnVisibleProperty

IsWeekNumberSelectionEnabledProperty

Defines the IsWeekNumberSelectionEnabled property.

public static readonly DependencyProperty IsWeekNumberSelectionEnabledProperty

MaxSelectionCountProperty

Defines the MaxSelectionCount property.

public static readonly DependencyProperty MaxSelectionCountProperty

MaxViewModeProperty

Defines the MaxViewMode property.

public static readonly DependencyProperty MaxViewModeProperty

MaximumProperty

Defines the Maximum property.

public static readonly DependencyProperty MaximumProperty

MinimumProperty

Defines the Minimum property.

public static readonly DependencyProperty MinimumProperty

MonthItemTemplateProperty

Defines the MonthItemTemplate property.

public static readonly DependencyProperty MonthItemTemplateProperty

MonthItemsPanelTemplateProperty

Defines the MonthItemsPanelTemplate property.

public static readonly DependencyProperty MonthItemsPanelTemplateProperty

NavigationButtonStyleProperty

Defines the NavigationButtonStyle property.

public static readonly DependencyProperty NavigationButtonStyleProperty

SelectedDateProperty

Defines the SelectedDate property.

public static readonly DependencyProperty SelectedDateProperty

SelectionModeProperty

Defines the SelectionMode property.

public static readonly DependencyProperty SelectionModeProperty

TitleButtonStyleProperty

Defines the TitleButtonStyle property.

public static readonly DependencyProperty TitleButtonStyleProperty

TitleProperty

Defines the Title property.

public static readonly DependencyProperty TitleProperty

TodayButtonStyleProperty

Defines the TodayButtonStyle property.

public static readonly DependencyProperty TodayButtonStyleProperty

TodayButtonTextProperty

Defines the TodayButtonText property.

public static readonly DependencyProperty TodayButtonTextProperty

ViewResetModeProperty

Defines the ViewResetMode property.

public static readonly DependencyProperty ViewResetModeProperty

WeekNumberItemContainerStyleProperty

Defines the WeekNumberItemContainerStyle property.

public static readonly DependencyProperty WeekNumberItemContainerStyleProperty

WeekNumberItemTemplateProperty

Defines the WeekNumberItemTemplate property.

public static readonly DependencyProperty WeekNumberItemTemplateProperty

WeekNumberItemsPanelTemplateProperty

Defines the WeekNumberItemsPanelTemplate property.

public static readonly DependencyProperty WeekNumberItemsPanelTemplateProperty

YearItemTemplateProperty

Defines the YearItemTemplate property.

public static readonly DependencyProperty YearItemTemplateProperty

YearItemsPanelTemplateProperty

Defines the YearItemsPanelTemplate property.

public static readonly DependencyProperty YearItemsPanelTemplateProperty

Extension Methods