-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DatePicker doesnt fire for DateSelected event on same date #13156
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Maybe this issue is more we need a "null date" option so that there is a change. Or maybe we need a DateChanged and PickerClosed event? I see this PR does something: https://github.com/dotnet/maui/pull/9727/files?w=1 However it changes the property type and I think that is a bit breaking. We could use things like DateTime.MinDate instead... |
A nullable date would be ideal, i actually discovered this while creating my own nullable datepicker The event is DateSelected not DateChanged it should trigger on any date selected not just changes |
This comment was marked as off-topic.
This comment was marked as off-topic.
Here's a workaround that should work on ios/android/winui Basically the date is always passed back up into the xplat layer but the BP doesn't fire a property changed so you just need to intercept via the interface. I'm not really sure how to make this work on catalyst though. On catalyst the event only fires when the value is changed and I couldn't figure out a way to detect when the dialog is opened and then closed. I think on catalyst you might have to get clever with it, like, have two controls on the screen and the non visible one opens the dialog. Unless someone knows of a way to make it work? AFAIK
ValueChanged doesn't fire though when the Value hasn't changed. using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
namespace DateChanger
{
public class CustomDatePicker : DatePicker, IDatePicker
{
public CustomDatePicker()
{
}
protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
base.OnHandlerChanging(args);
#if WINDOWS
if (args.OldHandler is IDatePickerHandler dph)
{
dph.PlatformView.Closed -= PlatformView_Closed;
}
#endif
}
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
if (Handler is IDatePickerHandler dphNew)
{
#if WINDOWS
dphNew.PlatformView.Closed += PlatformView_Closed;
#endif
}
}
#if WINDOWS
private void PlatformView_Closed(object sender, object e)
{
OnPropertyChanged(nameof(Date));
}
#endif
DateTime IDatePicker.Date
{
get => Date;
set
{
Date = value;
OnPropertyChanged(nameof(Date));
}
}
}
} |
Here's a workaround that should work.
|
This is still an issue, and the same for the TimePicker. its been over a year and still no fix. Used the Workaround suggested by @its-AliRaza . |
Sorry for being so insistent on this. The "workaround" shared here also does not cover all scenarios (e.g. when Date/TimePicker has previously been set to a different date than the default DateTime.Today.Date). It would also suffice to have a way to distinguish whether the user closed the Picker with "Cancel" or "Ok", but there is currently no method or event for differentiating between the scenario Cancel and Ok after selecting the same date as before. This issue is of high importance to a significant number of users, as can be deduced from the large amount of interaction and duplicates that are being created. Thank you again for your consideration. |
I suggest replacing Edit: analogous workaround for TimePicker (if anyone needs it): public class TimePickerWrapped : TimePicker, ITimePicker
{
TimeSpan ITimePicker.Time
{
get => Time;
set
{
if (value == Time)
{
Time += TimeSpan.FromSeconds(1);
}
Time = value;
OnPropertyChanged(nameof(Time));
}
}
} |
@StepKie thanks alot , you saved my time |
Description
The DatePicker has a default date of todays date, if someone selects that same date the dialog closes but the DateSelected doesn't fire
If you didn't pass in an initial date this effectively prevents a user from selecting today's date, if you do have a date bound it prevents selecting that date which means any extra code in the DateSelected event doesn't fire
This is related to #9180 though that was Android specific and for .Net 6
Steps to Reproduce
Link to public reproduction project repository
https://github.com/duindain/DateChanger
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, I was not able test on other platforms
Affected platform versions
Android 11 and up, WindowsSDK 10.0.19041, iOS 16.1
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: