-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
area-controls-datetimepickerDatePicker, TimePickerDatePicker, TimePickerdelighterproposal/opent/enhancement ☀️New feature or requestNew feature or request
Milestone
Description
Merging #1847
Summary
DatePicker
andTimePicker
should use the newDateOnly
andTimeOnly
structs instead ofDateTime
- The new fields should be nullable
- The new fields should be added to the Core implementation of MAUI
- The old properties should continue to exist in Controls, be marked as Obsolete, and wrap the new properties from Core
API Proposed:
Core:
public partial interface IDatePicker
{
DateOnly? Value { get; set; }
DateOnly? MinimumValue { get; }
DateOnly? MaximumValue { get; }
}
public partial interface ITimePicker
{
TimeOnly? Value { get; }
}
Controls:
public partial class DatePicker
{
DateOnly? Value { get; set; }
DateOnly? MinimumValue { get; set; }
DateOnly? MaximumValue { get; set; }
[Obsolete($"Use {nameof(Value)} instead.")]
DateTime Date
{
get => Value?.ToDateTime(TimeOnly.MinValue) ?? DateTime.MinValue;
set => Value = DateOnly.FromDateTime(value);
}
[Obsolete($"Use {nameof(MinimumValue)} instead.")]
DateTime MinimumDate
{
get => MinimumValue?.ToDateTime(TimeOnly.MinValue) ?? DateTime.MinValue;
set => MinimumValue = DateOnly.FromDateTime(value);
}
[Obsolete($"Use {nameof(MaximumValue)} instead.")]
DateTime MaximumDate
{
get => MaximumValue?.ToDateTime(TimeOnly.MinValue) ?? DateTime.MinValue;
set => MaximumValue = DateOnly.FromDateTime(value);
}
}
public partial class TimePicker
{
TimeOnly? Value { get; set; }
[Obsolete($"Use {nameof(Value)} instead.")]
TimeSpan Time
{
get => Value?.ToTimeSpan() ?? TimeSpan.Zero;
set => Value = TimeOnly.FromTimeSpan(value);
}
}
ORIGINAL POST:
Summary
I wish DatePicker
had a Date property that was nullable, so that we could use it for optional dates.
API Changes
My suggestion is to follow how UWP/WinUI resolved this issue in a backward-compatible way: They added another property.
public System.DateOnly? SelectedDate { get; set; }
It would go in both DatePicker
and IDatePicker (which doesn't need to be back-compat).
By the way, I used the new DateOnly instead of DateTime
. But I'm fine if that's not feasible.
Intended Use Case
Currently, it is a pain to build an app that allows users to provide an optional date. One workaround is to add a checkbox to "activate" entering that date, but that is really not user-friendly.
cschwarz, mtsrdr, Vroomer, mattjohnsonpint, kronic and 35 moretednyberg, sjd2021, vitorgatti, janusw, LeoJHarris and 2 more
Metadata
Metadata
Assignees
Labels
area-controls-datetimepickerDatePicker, TimePickerDatePicker, TimePickerdelighterproposal/opent/enhancement ☀️New feature or requestNew feature or request