Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms default DatePicker value?

How can I set a default or starting value for a Xamarin.Forms DatePicker?

At the moment, it begins on January 1st, 1900. This isn't a very useful date, and worse, a user has to scroll needlessly to get the right year, then the right month.

I'd like the default date to be the current date. I know how to get the current date, and I can set MinimumDate attribute of the DatePicker tag in the .xaml. This will make the current date the start date of the picker, but then I can't go back to a previous year or month.

Thanks,

like image 735
SteveFry Avatar asked Dec 03 '22 21:12

SteveFry


1 Answers

You can just set Date property directly on xaml:

<DatePicker x:Name="datePicker" Date="{x:Static system:DateTime.Today}" />

you need to use

xmlns:system="clr-namespace:System;assembly=mscorlib"
like image 93
Giancarlo Melis Avatar answered Dec 23 '22 06:12

Giancarlo Melis