Search code examples
c#datepickerxamarin.forms

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,


Solution

  • 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"