sahithi
sahithi

Reputation: 1089

Picker item source binding from view model

I am trying to bind the values for a picker from a model in view model, there I am getting path of the model instead of the values.

<Picker x:Name="LocationPicker"
    Title="Location" HeightRequest="40"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand"
    SelectedItem="{Binding Location}"
    ItemsSource="{Binding MaintainRoomTypes}"/>

Here is my view model code:

if (jobDetailsForFitter != null)
{
    WindowDetails = new WindowDetailsModel
    {
        Windows = jobDetailsForFitter.Windows,
        Locations = jobDetailsForFitter.Locations,
        RoomTypes = jobDetailsForFitter.RoomTypes,
        AddFiles = jobDetailsForFitter.AddFiles
    };

    Locations = jobDetailsForFitter.Locations;

    MaintainRoomTypes = jobDetailsForFitter.RoomTypes;

    await FitterService.Instance.LoadJobDetailsToLocalStore(jobDetailsForFitter, SelectedJob?.Id ?? 0);
}

how to bind itemsource to get list.

public List<Room> Locations { get; set; }
public List<RoomTypeModel> RoomTypes { get; set; }

Upvotes: 3

Views: 4296

Answers (1)

Sandesh Acharya
Sandesh Acharya

Reputation: 166

You have to define ItemDisplayBinding property to Picker.

For eg:

public class Room
{
public string RoomNumber { private set; get; }
public string RoomName { private set; get; }
}

And you want to display RoomName in Picker

<Picker ItemsSource="{Binding Room}" ItemDisplayBinding="{Binding RoomName}"/>

Hope this will solve your problem.

Upvotes: 7

Related Questions