Forum Xamarin Xamarin.Forms

Xamarin.Forms UWP DatePicker Max/Min Date Bug

I have noticed that on UWP when creating a xamarin.Forms DatePicker with a Max and Min date set, the DatePicker will allow a date to be entered outside of that range. Once the out of range date is confirmed in the picker the Binding will then snap back to the boundary of the min or max but the UI will not update to show that the date has been changed.

So say I have a date range of January 1st 2020 through June 30th 2020 and I choose a date of July 1st 2020, the Date picker will allow me to confirm this date but then behind the scenes will set the Binding value back to June 30th 2020. However, the Date picker UI will not update and will still show July 1st 2020.

There is already an issue filed for this bug here

But I am in need of a fix while it is still in development, has anyone found a workaround for this?

Answers

  • jezhjezh Member, Xamarin Team Xamurai
    edited March 10

    the DatePicker will allow a date to be entered outside of that range

    When you say 'Max and Min date set', do you mean the Max and Min date or the MaxYear and MinYear?
    In uwp,when we check Properties of DatePicker, there is no such property of Max and Min date.

  • JonathanCook.8900JonathanCook.8900 USMember ✭✭
    Thanks for the response. Yea, I'm aware that the uwp date picker only allows a min and max year. I'm hoping that they replace it with a calendar view that will support a max and min date. But the fact remains that the xamarin control calls it a min and max date and in uwp apparently still does something to snap you back into the bounds of the range you input, it just doesn't update the ui. I'm fine with this implementation of it as long as the ui updates when you click away from the control. So that's what I'm trying to see, has anyone found a work around for that bug
  • jezhjezh Member, Xamarin Team Xamurai

    If it is convenient for you , could you please post a basic demo or some code snippet so that we can help you better?

  • JonathanCook.8900JonathanCook.8900 USMember ✭✭

    Sorry it took me a bit to get some time to whip up a demo but here you go:
    https://github.com/JCookVF/DatePickerDemo.git

    You'll notice in the demo if you run on uwp it has a datepicker and a label underneath both bound to the Date property on the vm. When a date outside the Max min range is entered it will snap the bound value back to the closest min max value. However, the datepicker will not update its ui, but the label underneath will.

  • jezhjezh Member, Xamarin Team Xamurai

    We tested your code in uwp platform, for this question, when we set the date and exceed the range(MaximumDate and MinimumDate), the interface will be updated only if the Year value changes.

    And these are the only two properties MaxYear and MinYear in UWP,which all relative to Year.So this is should be the reason for this question.

    So we can only wait for Xamarin developers to update the latest features in UWP.

  • JonathanCook.8900JonathanCook.8900 USMember ✭✭

    But in my Demo the date max and min range are confined to the same year. There would be no changing of the year. Yet, you see that the actual bound Date does get automatically set back to the Max or Min date if you exceed the range, right? Would there not be a way to create a custom renderer that would just force update the UI when date gets automatically corrected?

  • jezhjezh Member, Xamarin Team Xamurai

    We will consult with our developers and get back to you.

Sign In or Register to comment.