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
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
.If it is convenient for you , could you please post a basic demo or some code snippet so that we can help you better?
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.
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
andMinYear
in UWP,which all relative toYear
.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.
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?
We will consult with our developers and get back to you.