How to load data in Xamarin.Forms SfPicker?
You can add a collection to picker at run time by adding it when picker is open on the dialog mode. The following steps explain how to load data in into Xamarin.Forms SfPicker.
Step 1: Add the necessary assemblies in the .NET Standard, Android, iOS, and UWP projects. Refer to this UG documentation to know more about the assemblies required for adding SfPicker to your project.
Step 2: Add a button to ContentPage as mentioned in the following code.
XAML:
<Button x:Name="button" Clicked="button_Clicked" Text="Open Picker"> </Button>
Step 3: Add the SfPicker control below the button with PickerMode as Dialog as mentioned in the following code.
XAML:
<syncfusion:SfPicker x:Name="picker" HeaderText="Select a country" PickerMode="Dialog" PickerHeight="280" PickerWidth="250" Opened="picker_Opened" WidthRequest="250" IsOpen="False"/>
Step 4: On button click, change the IsOpen property of SfPicker as mentioned in the following code.
C#:
private void button_Clicked(object sender, EventArgs e)
{
picker.IsOpen = true;
}
Step 5: On the SfPicker opened event, load items to picker.
C#:
private void picker_Opened(object sender, EventArgs e)
{
NameInfo name = new NameInfo();
picker.ItemsSource = name.Names;
}
Output image:
|
Sample for loading data into Xamarin.Forms SfPicker can be downloaded from this link: Sample.
Conclusion
I hope you enjoyed learning about how how to load the data in to Xamarin.Forms SfPicker when it opens. You can refer to our Xamarin.Forms Picker feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications. You can also explore our Xamarin.Forms Picker example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!
