khush
khush

Reputation: 161

Xamarin Forms Picker Item source binding in Xaml

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?

Upvotes: 5

Views: 15890

Answers (4)

Josue Martinez
Josue Martinez

Reputation: 436

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>

Upvotes: 0

deadlydog
deadlydog

Reputation: 24394

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.

Upvotes: 0

JordanMazurke
JordanMazurke

Reputation: 1123

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.

Upvotes: 2

Josh
Josh

Reputation: 12566

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.

Upvotes: 1

Related Questions