Xamarin.forms 从选择器中选择ID
我从API获取picker中的值,文本和值是我声明的两个字段!我可以看到它的价值!我希望无论何时从中选择项,我都能够获取该字段的相应值Xamarin.forms 从选择器中选择ID,xamarin.forms,Xamarin.forms,我从API获取picker中的值,文本和值是我声明的两个字段!我可以看到它的价值!我希望无论何时从中选择项,我都能够获取该字段的相应值 async void CallInspectionMaster() { string Url = "192.168.xx.xx/api/QMSin/GetInspectionMasterList"; var data = await Url.GetJson
async void CallInspectionMaster()
{
string Url = "192.168.xx.xx/api/QMSin/GetInspectionMasterList";
var data = await Url.GetJsonAsync<List<MyClass>>();
InspectionMasterPicker.ItemsSource = data;
InspectionMasterPicker.ItemDisplayBinding = new Binding("Text");
Binding selecteditemx = new Binding("InspectionMaster");
selecteditemx.Mode = BindingMode.TwoWay;
selecteditemx.Source = InspectionMasterPicker;
}
public class MyClass
{
public string Value { get; set; }
public string Text { get; set; }
}
async void CallInspectionMaster()
{
字符串Url=“192.168.xx.xx/api/QMSin/GetInspectionMasterList”;
var data=await Url.GetJsonAsync();
InspectionMasterPicker.ItemsSource=数据;
InspectionMasterPicker.ItemDisplayBinding=新绑定(“文本”);
Binding selecteditemx=新绑定(“检查主机”);
选择editemx.Mode=BindingMode.TwoWay;
选择editemx.Source=InspectionMasterPicker;
}
公共类MyClass
{
公共字符串值{get;set;}
公共字符串文本{get;set;}
}
我必须显示文本,但获取值,以便我可以将其传递给其他函数!如何执行此操作?为
SelectedIndexChanged
事件分配一个处理程序
InspectionMasterPicker.SelectedIndexChanged += PickerSelect;
然后创建处理程序
protected void PickerSelect(object sender, EventArgs args)
{
var item = (MyClass)InspectionMasterPicker.SelectedItem;
...
}
文档中包含了一个这将为我显示的所选项目提供文本,但我需要与之关联的值!看这个!{“文本”:“奥德赛工艺(私人)有限公司”,“价值”:“C20171”},{“文本”:“里约时装服饰有限公司”,“价值”:“C20172”}]这不起作用!var item=(MyClass)InspectionMasterPicker.Items[InspectionMasterPicker.SelectedIndex];所以我写了这个!var item=InspectionMasterPicker.Items[InspectionMasterPicker.SelectedIndex];项目应该是MyClass类型,它有值和文本属性,但这给了我一个红色的错误,不允许我使用它!“红色错误”非常有用。实际的错误消息是什么?文本已经来了,我需要关联值!