Primary WPF APIs:
DatePickerCalendarPrimary Avalonia APIs:
CalendarDatePickerDatePickerTimePickerCalendar| WPF | Avalonia |
|---|---|
DatePicker.SelectedDate (DateTime?) |
DatePicker.SelectedDate (DateTimeOffset?) |
date drop-down bound to DateTime? models |
CalendarDatePicker.SelectedDate (DateTime?) |
| date selector with drop-down calendar | CalendarDatePicker |
| inline calendar | Calendar |
| time selection (custom controls/toolkit in WPF) | built-in TimePicker |
WPF XAML:
<StackPanel>
<DatePicker SelectedDate="{Binding DueDate, Mode=TwoWay}" />
<Calendar SelectedDate="{Binding DueDate, Mode=TwoWay}" />
</StackPanel>
Avalonia XAML:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:ScheduleViewModel">
<Grid RowDefinitions="Auto,Auto,Auto,*" RowSpacing="8">
<DatePicker Grid.Row="0"
SelectedDate="{CompiledBinding DueDateOffset, Mode=TwoWay}" />
<CalendarDatePicker Grid.Row="1"
SelectedDate="{CompiledBinding DueDate, Mode=TwoWay}" />
<TimePicker Grid.Row="2"
SelectedTime="{CompiledBinding DueTime, Mode=TwoWay}" />
<Calendar Grid.Row="3"
SelectionMode="SingleDate"
SelectedDate="{CompiledBinding DueDate, Mode=TwoWay}" />
</Grid>
</UserControl>
using System;
using Avalonia.Controls;
var dateOffset = new DatePicker { SelectedDate = DateTimeOffset.Now };
var date = new CalendarDatePicker { SelectedDate = DateTime.Today };
var time = new TimePicker { SelectedTime = TimeSpan.FromHours(9) };
var calendar = new Calendar
{
SelectionMode = CalendarSelectionMode.SingleDate,
SelectedDate = DateTime.Today
};
DateTime? (calendar-like controls) versus DateTimeOffset? (DatePicker) explicitly.TimePicker rather than ad-hoc text input.SelectionMode and communicate single/range semantics clearly.