Table of Contents

Class CalendarDatePicker

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A date selection control that allows the user to select dates from a drop down calendar.

[TemplatePart("PART_Button", typeof(Button))]
[TemplatePart("PART_Calendar", typeof(Calendar))]
[TemplatePart("PART_Popup", typeof(Popup))]
[TemplatePart("PART_TextBox", typeof(TextBox))]
[PseudoClasses(new string[] { ":flyout-open", ":pressed" })]
public class CalendarDatePicker : TemplatedControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
Inheritance
CalendarDatePicker
Implements
Inherited Members
Extension Methods

Constructors

CalendarDatePicker()

Initializes a new instance of the CalendarDatePicker class.

public CalendarDatePicker()

Fields

CustomDateFormatStringProperty

Defines the CustomDateFormatString property.

public static readonly StyledProperty<string> CustomDateFormatStringProperty

Field Value

StyledProperty<string>

DisplayDateEndProperty

Defines the DisplayDateEnd property.

public static readonly StyledProperty<DateTime?> DisplayDateEndProperty

Field Value

StyledProperty<DateTime?>

DisplayDateProperty

Defines the DisplayDate property.

public static readonly StyledProperty<DateTime> DisplayDateProperty

Field Value

StyledProperty<DateTime>

DisplayDateStartProperty

Defines the DisplayDateStart property.

public static readonly StyledProperty<DateTime?> DisplayDateStartProperty

Field Value

StyledProperty<DateTime?>

FirstDayOfWeekProperty

Defines the FirstDayOfWeek property.

public static readonly StyledProperty<DayOfWeek> FirstDayOfWeekProperty

Field Value

StyledProperty<DayOfWeek>

HorizontalContentAlignmentProperty

Defines the HorizontalContentAlignment property.

public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty

Field Value

StyledProperty<HorizontalAlignment>

IsDropDownOpenProperty

Defines the IsDropDownOpen property.

public static readonly StyledProperty<bool> IsDropDownOpenProperty

Field Value

StyledProperty<bool>

IsTodayHighlightedProperty

Defines the IsTodayHighlighted property.

public static readonly StyledProperty<bool> IsTodayHighlightedProperty

Field Value

StyledProperty<bool>

SelectedDateFormatProperty

Defines the SelectedDateFormat property.

public static readonly StyledProperty<CalendarDatePickerFormat> SelectedDateFormatProperty

Field Value

StyledProperty<CalendarDatePickerFormat>

SelectedDateProperty

Defines the SelectedDate property.

public static readonly StyledProperty<DateTime?> SelectedDateProperty

Field Value

StyledProperty<DateTime?>

TextProperty

Defines the Text property.

public static readonly StyledProperty<string?> TextProperty

Field Value

StyledProperty<string>

UseFloatingWatermarkProperty

Defines the UseFloatingWatermark property.

public static readonly StyledProperty<bool> UseFloatingWatermarkProperty

Field Value

StyledProperty<bool>

VerticalContentAlignmentProperty

Defines the VerticalContentAlignment property.

public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty

Field Value

StyledProperty<VerticalAlignment>

WatermarkProperty

Defines the Watermark property.

public static readonly StyledProperty<string?> WatermarkProperty

Field Value

StyledProperty<string>

Properties

BlackoutDates

Gets a collection of dates that are marked as not selectable.

public CalendarBlackoutDatesCollection? BlackoutDates { get; }

Property Value

CalendarBlackoutDatesCollection

A collection of dates that cannot be selected. The default value is an empty collection.

CustomDateFormatString

public string CustomDateFormatString { get; set; }

Property Value

string

DisplayDate

Gets or sets the date to display.

public DateTime DisplayDate { get; set; }

Property Value

DateTime

The date to display. The default is Today.

Exceptions

ArgumentOutOfRangeException

The specified date is not in the range defined by DisplayDateStart and DisplayDateEnd.

DisplayDateEnd

Gets or sets the last date to be displayed.

public DateTime? DisplayDateEnd { get; set; }

Property Value

DateTime?

The last date to display.

DisplayDateStart

Gets or sets the first date to be displayed.

public DateTime? DisplayDateStart { get; set; }

Property Value

DateTime?

The first date to display.

FirstDayOfWeek

Gets or sets the day that is considered the beginning of the week.

public DayOfWeek FirstDayOfWeek { get; set; }

Property Value

DayOfWeek

A DayOfWeek representing the beginning of the week. The default is Sunday.

HorizontalContentAlignment

Gets or sets the horizontal alignment of the content within the control.

public HorizontalAlignment HorizontalContentAlignment { get; set; }

Property Value

HorizontalAlignment

IsDropDownOpen

Gets or sets a value indicating whether the drop-down Calendar is open or closed.

public bool IsDropDownOpen { get; set; }

Property Value

bool

True if the Calendar is open; otherwise, false. The default is false.

IsTodayHighlighted

Gets or sets a value indicating whether the current date will be highlighted.

public bool IsTodayHighlighted { get; set; }

Property Value

bool

True if the current date is highlighted; otherwise, false. The default is true.

SelectedDate

Gets or sets the currently selected date.

public DateTime? SelectedDate { get; set; }

Property Value

DateTime?

The date currently selected. The default is null.

Exceptions

ArgumentOutOfRangeException

The specified date is not in the range defined by DisplayDateStart and DisplayDateEnd, or the specified date is in the BlackoutDates collection.

SelectedDateFormat

Gets or sets the format that is used to display the selected date.

public CalendarDatePickerFormat SelectedDateFormat { get; set; }

Property Value

CalendarDatePickerFormat

The format that is used to display the selected date. The default is Short.

Exceptions

ArgumentOutOfRangeException

An specified format is not valid.

Text

Gets or sets the text that is displayed by the CalendarDatePicker.

public string? Text { get; set; }

Property Value

string

The text displayed by the CalendarDatePicker.

Exceptions

FormatException

The text entered cannot be parsed to a valid date, and the exception is not suppressed.

ArgumentOutOfRangeException

The text entered parses to a date that is not selectable.

UseFloatingWatermark

Gets or sets a value indicating whether the Watermark will still be shown above the Text even after a text value is set.

public bool UseFloatingWatermark { get; set; }

Property Value

bool

VerticalContentAlignment

Gets or sets the vertical alignment of the content within the control.

public VerticalAlignment VerticalContentAlignment { get; set; }

Property Value

VerticalAlignment

Watermark

Gets or sets the placeholder or descriptive text that is displayed even if the Text property is not yet set.

public string? Watermark { get; set; }

Property Value

string

Methods

Clear()

Clear SelectedDate.

public void Clear()

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnDateValidationError(CalendarDatePickerDateValidationErrorEventArgs)

Raises the DateValidationError event.

protected virtual void OnDateValidationError(CalendarDatePickerDateValidationErrorEventArgs e)

Parameters

e CalendarDatePickerDateValidationErrorEventArgs

A CalendarDatePickerDateValidationErrorEventArgs that contains the event data.

OnGotFocus(GotFocusEventArgs)

Called before the GotFocus event occurs.

protected override void OnGotFocus(GotFocusEventArgs e)

Parameters

e GotFocusEventArgs

The event args.

OnKeyUp(KeyEventArgs)

Called before the KeyUp event occurs.

protected override void OnKeyUp(KeyEventArgs e)

Parameters

e KeyEventArgs

The event args.

OnLostFocus(RoutedEventArgs)

Called before the LostFocus event occurs.

protected override void OnLostFocus(RoutedEventArgs e)

Parameters

e RoutedEventArgs

The event args.

OnPointerCaptureLost(PointerCaptureLostEventArgs)

Called before the PointerCaptureLost event occurs.

protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)

Parameters

e PointerCaptureLostEventArgs

The event args.

OnPointerPressed(PointerPressedEventArgs)

Called before the PointerPressed event occurs.

protected override void OnPointerPressed(PointerPressedEventArgs e)

Parameters

e PointerPressedEventArgs

The event args.

OnPointerReleased(PointerReleasedEventArgs)

Called before the PointerReleased event occurs.

protected override void OnPointerReleased(PointerReleasedEventArgs e)

Parameters

e PointerReleasedEventArgs

The event args.

OnPointerWheelChanged(PointerWheelEventArgs)

Called before the PointerWheelChanged event occurs.

protected override void OnPointerWheelChanged(PointerWheelEventArgs e)

Parameters

e PointerWheelEventArgs

The event args.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

UpdateDataValidation(AvaloniaProperty, BindingValueType, Exception?)

Called to update the validation state for properties for which data validation is enabled.

protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)

Parameters

property AvaloniaProperty

The property.

state BindingValueType

The current data binding state.

error Exception

The current data binding error, if any.

UpdatePseudoClasses()

Updates the visual state of the control by applying latest PseudoClasses.

protected void UpdatePseudoClasses()

Events

CalendarClosed

Occurs when the drop-down Calendar is closed.

public event EventHandler? CalendarClosed

Event Type

EventHandler

CalendarOpened

Occurs when the drop-down Calendar is opened.

public event EventHandler? CalendarOpened

Event Type

EventHandler

DateValidationError

Occurs when Avalonia.Controls.DatePicker.Text is assigned a value that cannot be interpreted as a date.

public event EventHandler<CalendarDatePickerDateValidationErrorEventArgs>? DateValidationError

Event Type

EventHandler<CalendarDatePickerDateValidationErrorEventArgs>

SelectedDateChanged

Occurs when the SelectedDate property is changed.

public event EventHandler<SelectionChangedEventArgs>? SelectedDateChanged

Event Type

EventHandler<SelectionChangedEventArgs>