Search code examples
c#xamarinxamarin.formsxamarin.androidxamarin.ios

Xamarin Forms Bind List<myObject> to Picker


I have a problem. I created this Picker:

<Picker SelectedIndex="0" x:Name="pickerMode" Margin="30,0,30,0" />

And in my background code I set the ItemSource like this:

List<Mode> modeList = new List<Mode>();
Mode mode = new Mode
{
    Id = 0,
    Name = "Item1",
    Type = "Test"
}

modeList.Add(mode)
pickerMode.ItemsSource = modeList;

But when I launch the App, the picker stays empty. I want the Picker to show the Name of every Mode in that List.

What am I doing wrong?


Solution

  • Add this property in the XAML on your Picker ItemDisplayBinding="{Binding Name}"