When using date pickers, sometimes we have the need to be able to set no value at all. For that just created a control to a support nullable date value but also provide the possibility to clear it.
Using it is really simple, let’s do it step by step:
1-In your Forms project add this control
In the code above created a new property called NullableDate, we are going to use this property instead of the Date Property.
2-In the Android project add this NullableDatePickerRenderer
3-In the iOS project add this NullableDatePickerRenderer
4-Use the control
As you can see here instead of using the Date property you will use a new property called NullableDate.
Also, if you want to change the default placeholder empty value you can do it by using the PlaceHolder property.
You can see the full source code used here:
https://github.com/CrossGeeks/ClearableDatePickerSample
Happy coding! 🙂
10 Comments
How did you create spinner mode for your datepicker in droid project?
What version of android are you running on ?
I tried on my note5 running in Android 7.0 API 24 and Samsung Tablet E running in Android 6.0 API 23, all I get is calendar mode for datepicker.
That’s because I’m using an old Android version – 4.4
This works perfect but date it shown with time so How to remove 12:00:00Am from the date picker text eg; 12/03/18 12:00;00 AM
Check the NullableDatePicker.cs file in the constructor I’m setting Format = “d” , just change this format for whatever you prefer.
https://docs.microsoft.com/es-es/dotnet/standard/base-types/standard-date-and-time-format-strings
Wao, Simply excellent. De lo mio!!!
Thanks for sharing it!
In case someone has the same issue I had: I changed the placeholder to “\”Select…\”” with the extra escaped quote chars to make it display the text properly.
in case anyone needs any assistance with customizations dependent on platform, or how to display a true empty string on clear instead of /,/./ feel free to message me. great control.
On first binding the value is not populated. How to resolve this?
But you mean, after save the actual date and clicking in done?
Also in what platform?
Dope article. Thanks