How to open the SfPicker in button click action in Xamarin.Forms
The Xamarin.Forms SfPicker provides support to open a picker in dialog mode. This can be achieved by setting the PickerMode property of SfPicker to Dialog. When setting this property to Dialog, you can open a picker only in click event. In the click event, you need to set the IsOpen property of SfPicker to true. The following steps explain how to open the Xamarin.Forms SfPicker in dialog mode:
Step 1: Initialize the Xamarin.Forms SfPicker in XAML page with the properties need to be assigned.
Step 2: Set the DialogMode property of Xamarin.Forms SfPicker to Dialog.
Step 3: Add the button control and handle the click event. Inside the click event, set the IsOpen property of SfPicker to true.
XAML:
<StackLayout> <Button Text="Open Picker" Clicked="Handle_Clicked"></Button> <syncfusion:SfPicker x:Name="picker" IsEnabled="True" ItemsSource="{Binding Colors}" PickerHeight="300" PickerMode="Dialog" PickerWidth="200" HeaderText="Select a Color" ShowHeader="True" ShowFooter="True" UnSelectedItemTextColor="Black" VerticalOptions="Center"> </syncfusion:SfPicker> </StackLayout>
C#:
void Handle_Clicked(object sender, System.EventArgs e) { picker.IsOpen = true; }
You can find the sample in following link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PickerDialogMode-1448091611.zip
Output: