I need to allow user to enter their credit card expiration date. For this I have to show them date picker with only month and year options. I am using format="MM-yyyy", but no luck. Can anyone help me ? Thanks.
For Android, it's not so simple, so you'd have to use reflection to modify the component directly, the example below is for removing the year, but you in theory could use the same approach for removing the day.
We did something similar (for time rather than date) by creating a custom renderer for each platform, with the renderer replacing the native control. It might be worth looking at the Xamarin.Forms source code to see what Xamarin used, but our current implementation uses:
Android - Android.Widget.EditText and AlertDialog
iOS - UITextField and UIPickerView
UWP - Windows.UI.Xaml.Controls.UserControl and Windows.UI.Xaml.Controls.Flyout
Thanks JohnHardman. I've created it successfully with iOS platform but still don't know "where to go" with Android caused I only have some development experiences with iOS only .
Answers
I think you have to use a customer renderers
I'm looking into the same problem. It seems that even natively you'd have to do a few things.
For iOS you'd have to create your own UIPickerView and then set sources for month and year manually
http://stackoverflow.com/questions/3348247/uidatepicker-select-month-and-year
For Android, it's not so simple, so you'd have to use reflection to modify the component directly, the example below is for removing the year, but you in theory could use the same approach for removing the day.
http://stackoverflow.com/questions/10233760/remove-year-from-datepickerdialog
http://stackoverflow.com/questions/10401915/hide-year-field-in-android-datepicker
Sorry I don't have a copy and paste solution for you! But these are really good starting points.
Just adding to my answer, another thread which suggest the approaches above:
http://stackoverflow.com/questions/38016064/show-only-month-and-year-in-date-picker-in-xamarin-forms
Nobody has shared a solution for this yet, if I get around to working on this (it's fairly low in my backlog) i'll try to share code on GitHub.
Hi guys, did you find any solutions for this one? I'm being stuck with this task for days (headbang)
We did something similar (for time rather than date) by creating a custom renderer for each platform, with the renderer replacing the native control. It might be worth looking at the Xamarin.Forms source code to see what Xamarin used, but our current implementation uses:
Android - Android.Widget.EditText and AlertDialog
iOS - UITextField and UIPickerView
UWP - Windows.UI.Xaml.Controls.UserControl and Windows.UI.Xaml.Controls.Flyout
Thanks JohnHardman. I've created it successfully with iOS platform but still don't know "where to go" with Android caused I only have some development experiences with iOS only
.
I solved this but only for android using a renderer:
https://forums.xamarin.com/discussion/37978/hide-day-in-datepicker?#Comment_373775
@DuongNguyen.0603 Can you please provide the source code
I need to show only month and year in both android and ios 's Datepicker