Sometimes you stumble upon these gems that you didn’t know they existed.
Like I did today…
The ‘problem’ with the Picker
You might have noticed that when you are binding to the SelectedItem of a Picker in Xamarin Forms, that on iOS the value of the bound property already changes when the user is scrolling through the list of options, even without explicitly having tapped the ‘Done’ button.
Platform specifics to the rescue
In XAML this looks something like this:
<Picker ItemsSource="{Binding Options}" SelectedItem="{Binding Result}" ItemDisplayBinding="{Binding Label}" iOSSpecific:Picker.UpdateMode="WhenFinished" />
For this I added this namespace in my XAML:
xmlns:iOSSpecific="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
If we would want to do the same thing in code, we can do it as follows:
myPicker.On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUpdateMode(UpdateMode.WhenFinished);
Cool! Yet another Xamarin Forms gem I didn’t know about! 🙂
July 16, 2017 at 5:18 pm
Sir, you can try UnFocused event, it worked same.
Forgive my poor english, i hope you can see it.
July 16, 2017 at 5:25 pm
Indeed, you can. That was one of the work arounds I wrote before I found this solution. It felt a bit like a hack an didn’t play nice with databinding neither (I ended up with using 2 properties on my viewmodel and stuff).
With this solution, in combination with databinding, I don’t have the feeling I’m hacking my way around as this is a thing from the framework itself.
July 27, 2017 at 3:50 pm
Any way to include a cancel button also?
July 28, 2017 at 9:33 pm
Excellent solution, thanks for sharing.
November 27, 2017 at 8:37 pm
This!!!!!! Thanks for sharing!
December 13, 2017 at 6:45 am
You’re great!!!!! I have been wondering for this since long many weeks
February 7, 2018 at 10:27 pm
Excelente Solución, gracias.
July 6, 2018 at 2:01 am
So this only works on Picker, not DatePicker or TimePicker?
June 10, 2019 at 4:03 pm
No, looks like this is still considered an enhancement for DatePicker or TimePicker:
https://bugzilla.xamarin.com/show_bug.cgi?id=57859