简体   繁体   中英

Xamarin.Forms DatePicker not respecting Minimum / Maximum on WindowsPhone

It may be the order of my property setting or something, however I've tried multiple ways, and verified the properties prior to the function completing.

However, when I try the following:-

DatePicker datePicker1 = new DatePicker();
datePicker1.MinimumDate = DateTime.Now.Date;
datePicker1.MaximumDate = DateTime.Now.Date.Add(new TimeSpan(7,0,0,0));
datePicker1.Date = DateTime.Now.Date;
datePicker1.Format = "MMM dd, yyyy";

On WindowsPhone when I test this, I can still select a date earlier than the minimum and maximum date values I set.

Actually from further testing with adding an event listener to DateSelected , I've noticed this control doing all sorts of weird things:-

So, my original date when i run is: Aug 03, 2015

Then I change the month to July, and click the tick. It then shows Jul 03, 2015 which is clearly less than my minimum date. I don't get any event raised via 'DateSelected' however it does change the UI with the date I've selected.

If I change the month then to June, no event raised, however display shows Jun 03,2015 .

If I change the month to October, I get an event raised, and the display shows Aug 10, 2015 which is my maximum date, so this is fine.

If I then change the month to June again, I get an event raised, and the display shows Aug 03, 2015 which is my minimum date.

I also don't appear to be able to trap a DateSelected property change as one doesn't appear to be firing on the UI update to try and handle this scenario another way.

Is there any way of getting this control to behave correctly? I'm using Xamarin.Forms 1.4.2 .

Please upgrade to 1.4.4.

Xamarin Forms 1.4.3 had many updates in regards to bug fixes around the DatePicker in Android and WinPhone but its best to upgrade all the way because 1.4.4 fixed many other issues as well.

The date picker issues fixed in 1.4.3 are

https://bugzilla.xamarin.com/show_bug.cgi?id=27537

https://bugzilla.xamarin.com/show_bug.cgi?id=28424

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM