Table of Contents

Class DatePicker

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A control to allow the user to select a date

[TemplatePart("PART_ButtonContentGrid", typeof(Grid))]
[TemplatePart("PART_DayTextBlock", typeof(TextBlock))]
[TemplatePart("PART_FirstSpacer", typeof(Rectangle))]
[TemplatePart("PART_FlyoutButton", typeof(Button))]
[TemplatePart("PART_MonthTextBlock", typeof(TextBlock))]
[TemplatePart("PART_PickerPresenter", typeof(DatePickerPresenter))]
[TemplatePart("PART_Popup", typeof(Popup))]
[TemplatePart("PART_SecondSpacer", typeof(Rectangle))]
[TemplatePart("PART_YearTextBlock", typeof(TextBlock))]
[PseudoClasses(new string[] { ":hasnodate" })]
public class DatePicker : TemplatedControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
Inheritance
DatePicker
Implements
Inherited Members
Extension Methods

Constructors

DatePicker()

public DatePicker()

Fields

DayFormatProperty

Define the DayFormat Property

public static readonly StyledProperty<string> DayFormatProperty

Field Value

StyledProperty<string>

DayVisibleProperty

Defines the DayVisible Property

public static readonly StyledProperty<bool> DayVisibleProperty

Field Value

StyledProperty<bool>

MaxYearProperty

Defines the MaxYear Property

public static readonly StyledProperty<DateTimeOffset> MaxYearProperty

Field Value

StyledProperty<DateTimeOffset>

MinYearProperty

Defines the MinYear Property

public static readonly StyledProperty<DateTimeOffset> MinYearProperty

Field Value

StyledProperty<DateTimeOffset>

MonthFormatProperty

Defines the MonthFormat Property

public static readonly StyledProperty<string> MonthFormatProperty

Field Value

StyledProperty<string>

MonthVisibleProperty

Defines the MonthVisible Property

public static readonly StyledProperty<bool> MonthVisibleProperty

Field Value

StyledProperty<bool>

SelectedDateProperty

Defines the SelectedDate Property

public static readonly StyledProperty<DateTimeOffset?> SelectedDateProperty

Field Value

StyledProperty<DateTimeOffset?>

YearFormatProperty

Defines the YearFormat Property

public static readonly StyledProperty<string> YearFormatProperty

Field Value

StyledProperty<string>

YearVisibleProperty

Defines the YearVisible Property

public static readonly StyledProperty<bool> YearVisibleProperty

Field Value

StyledProperty<bool>

Properties

DayFormat

public string DayFormat { get; set; }

Property Value

string

DayVisible

Gets or sets whether the day is visible

public bool DayVisible { get; set; }

Property Value

bool

MaxYear

Gets or sets the maximum year for the picker

public DateTimeOffset MaxYear { get; set; }

Property Value

DateTimeOffset

MinYear

Gets or sets the minimum year for the picker

public DateTimeOffset MinYear { get; set; }

Property Value

DateTimeOffset

MonthFormat

Gets or sets the month format

public string MonthFormat { get; set; }

Property Value

string

MonthVisible

Gets or sets whether the month is visible

public bool MonthVisible { get; set; }

Property Value

bool

SelectedDate

Gets or sets the Selected Date for the picker, can be null

public DateTimeOffset? SelectedDate { get; set; }

Property Value

DateTimeOffset?

YearFormat

Gets or sets the year format

public string YearFormat { get; set; }

Property Value

string

YearVisible

Gets or sets whether the year is visible

public bool YearVisible { get; set; }

Property Value

bool

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.

OnCreateAutomationPeer()

Returns a new, type-specific AutomationPeer implementation for the control.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

OnSelectedDateChanged(object?, DatePickerSelectedValueChangedEventArgs)

protected virtual void OnSelectedDateChanged(object? sender, DatePickerSelectedValueChangedEventArgs e)

Parameters

sender object
e DatePickerSelectedValueChangedEventArgs

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.

Events

SelectedDateChanged

Raised when the SelectedDate changes

public event EventHandler<DatePickerSelectedValueChangedEventArgs>? SelectedDateChanged

Event Type

EventHandler<DatePickerSelectedValueChangedEventArgs>