5
votes

I need to create states picker in my Xamarin Forms. I am using Xaml file for creating views.

Can any one help me to bind Picker in Xaml with item source?

4
The last time I checked there was no ItemSource binding property for the Picker in XAML. That said you should either do the binding in code or via a custom BindablePicker (e.g.: forums.xamarin.com/discussion/30801/…)Wizche
thecoshman - sometimes we have no clue where to start and come here for advice/samplesjlo-gmail

4 Answers

2
votes

The XLabs has an excellent example of a bindable picker that I have used in several projects to great affect:

https://github.com/XLabs/Xamarin-Forms-Labs

This will allow you to replicate the 'ItemsSource' functionality of the Listview.

1
votes

You won't be able to do this in XAML, as you can see here.

You'll have to load the data up in the code behind, using either their regular API, or something like this.

You can also serialize your list as a JSON or preferred format, and deserialize that and pass it to the Picker.

0
votes

This functionality did not previous exist, but it was recently added to the regular Xamarin.Forms Picker via the new ItemsSource and SelectedItem properties. It is currently in the pre-release NuGet package for version 2.3.4-pre1, but should be in the stable 2.3.4+ versions once it is released.

0
votes

As JordanMazurke commented, XLabs has it. Here is an example:

<ContentPage x:Class="XLabs.Samples.Pages.Controls.ExtendedPickerPage"
         xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
         Title="Picker">
<ContentPage.Content>
    <StackLayout x:Name="myStackLayout">
        <Label Text="Xaml:" />
        <controls:ExtendedPicker x:Name="myPicker"
                                 DisplayProperty="FirstName"
                                 ItemsSource="{Binding MyDataList}"
                                 SelectedItem="{Binding TheChosenOne}" />
    </StackLayout>
</ContentPage.Content>