Reputation: 281
Can i Trigger a Picker programatically?
I would like a button beside the picker that indicates that the picker is a clickable "dropdown". But how could I open the picker when the button is clicked?
Upvotes: 21
Views: 11145
Reputation: 1261
You can name the picker (e.g. myPicker) and call its Focus event. Do make sure that you're on the main thread at the time you're calling myPicker.Focus()
Upvotes: 19
Reputation: 24384
As @Hutjepower and this xamarin forums post mentions, the following code should work:
Device.BeginInvokeOnMainThread(() =>
{
if (yourPicker.IsFocused)
yourPicker.Unfocus();
yourPicker.Focus();
});
However I have found that it does not currently work on Windows 8.1 and UWP apps, at least in the latest 2.3.4-pre1 version of Xamarin.Forms. I haven't tested it on any phone/tablet devices yet though. Hopefully this bug will get fixed up in a later release. I have created a bug report for this problem.
Upvotes: 12
Reputation: 3678
Unfortunately not; the inner workings of the picker are almost entirely in the renderers and are not exposed via an API.
Upvotes: 1