我正在尝试从视图模型中的模型绑定选择器的值,在那里我得到模型的路径而不是值。
<Picker x:Name="LocationPicker"
Title="Location" HeightRequest="40"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
SelectedItem="{Binding Location}"
ItemsSource="{Binding MaintainRoomTypes}"/>
这是我的模型代码:
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);
}
如何绑定itemsource以获取列表。
public List<Room> Locations { get; set; }
public List<RoomTypeModel> RoomTypes { get; set; }
答案 0 :(得分:6)
您必须将ItemDisplayBinding
属性定义为Picker
。
例如:
public class Room
{
public string RoomNumber { private set; get; }
public string RoomName { private set; get; }
}
您想在选择器
中显示 RoomName<Picker ItemsSource="{Binding Room}" ItemDisplayBinding="{Binding RoomName}"/>
希望这能解决您的问题。