Monthly Archives: July 2017

Bind to Xamarin Picker but only update value after hitting Done on iOS

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.

Now in a particular app I’m developing, I -the product owner actually- didn’t want this behavior. Instead, the bound property should change its value ONLY when the user taps the Done button in the Picker. And so I started to try some stuff out…

Platform specifics to the rescue

Eventually, after trying some stuff and after I lost already too much time on this to be honest, I came across to the ‘ Picker.UpdateMode’ platform-specific. And with this, I can define when the change on my property should be triggered: Immediately  (the default) or WhenFinished  (when the user tapped the ‘Done’ button).
In XAML this looks something like this:

For this I added this namespace in my XAML:

If we would want to do the same thing in code, we can do it as follows:

Cool! Yet another Xamarin Forms gem I didn’t know about! 🙂