gpt4 book ai didi

xamarin - 来自 View 模型的选择器项源绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 05:45:25 25 4
gpt4 key购买 nike

我正在尝试从 View 模型中的模型绑定(bind)选择器的值,在那里我得到模型的路径而不是值。

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

这是我的 View 模型代码:

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);
}

如何绑定(bind)itemsource获取列表。

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

最佳答案

您必须为 Picker 定义 ItemDisplayBinding 属性。

例如:

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

并且您想在Picker中显示RoomName

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

希望这能解决您的问题。

关于xamarin - 来自 View 模型的选择器项源绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46174637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com