0

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.

Gans
  • 129
  • 2
  • 11

4 Answers4

1

As mentioned here:

No, this cannot be done using the stock UIDatePicker

As such, you'll have to make your own Xamarin Forms control, and implement it on each platform. Meaning you'll have to use a default UiPickerView on iOS, and the equivalent on Android (and Windows Phone?).

Community
  • 1
  • 1
Falgantil
  • 1,290
  • 12
  • 27
  • Unfortunately my target is Windows phone only :( – Gans Jun 24 '16 at 14:58
  • If it is solely a Windows Phone, then why are you making a Xamarin Forms app? – Falgantil Jun 24 '16 at 14:59
  • Right now our target is only Windows phone but after our first release we should target Android and ios too – Gans Jun 24 '16 at 15:25
  • @Gans Wow we usually do the exact opposite. Any specific reason why you are doing it that way? Just curious. – hvaughan3 Jun 24 '16 at 17:04
  • Perhaps they're a company that has WP company phones? In any case, my answer still stands. You need to make a custom control, and create the renderers yourself. – Falgantil Jun 24 '16 at 20:33
  • @hvaughan3 - I actually do Windows Phone first because the development experience is soooo much better. Then with transferring to iOS and Android it is only UI issues to deal with. – Adam Jun 25 '16 at 10:33
0

It would be a pain to customize each platform this. What I would recommend is to provide 2 regular text pickers, one with 01 - 12 or Jan - Dec whichever you prefer and the other with the next 20 years listed from today's year, so it dynamically updates as times goes on.

Side Note: 20 years seems to be the max most credit card providers would ever go, Amazon only goes to +20, but just letting you know there isn't a hard limit so there is a small possibility it could go further but very unlikely.

Adam
  • 16,089
  • 6
  • 66
  • 109
0

You should customise a UIPickerView to use two components and populate its rows with month and year symbols retrieved from NSDateFormatter. Hope that works out for you!

Imdad
  • 769
  • 1
  • 11
  • 31
0

You only need to type this:

<DatePicker Format="MM/yyyy" />

^^

Tathata
  • 29
  • 2