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?
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?
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.
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.
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>