xamarin 是否可以将键/值分配给选取器?

egdjgwm8  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(202)

我尝试使用一个类似html的选择器

<select>
<option value="KEY">Value</option>
</select>

然而我找不到任何与此相关的东西。我有一些沿着的东西

List<KeyValuePair<int, string>> KVP = {1: "test", 2: "test2"}

当前xAML:

<StackLayout x:Name="PickerStack">
                <Picker x:Name="DefaultPicker"
                        Title="---Select a map---" 
                        ItemsSource="{Binding GPXList_PickerList}" 
                        SelectedIndexChanged="PickerStack_Selected" 
                        SelectedItem="{Binding PickerStack_Selection}" />

当前后面的代码:

var ResultConvert = JsonConvert.DeserializeObject<GPSAPI_GPXList[]>(ResultJSON);
            List<int> gpxList_ID = ResultConvert.Select(x => x.gpxList_ID).ToList();
            List<string> gpxList_TrailHead_Name = ResultConvert.Select(x => x.gpxList_TrailHead_Name).ToList();
            GPXList_Dictionary = ResultConvert.ToDictionary(x => x.gpxList_ID, x => x.gpxList_TrailHead_Name);
//
            // call for my picker to be populated
            PickerView(GPXList_PickerItems);

        }

        //
        // fill the picker with retrieved API values
        public void PickerView(List<KeyValuePair<int, string>> PickerSource)
        {
            DefaultPicker.ItemsSource = PickerSource;
        }

        //
        // observe the PickerStack and retrieve values on change
        private void PickerStack_Selected(object sender, EventArgs e)
        {
            Picker PickerSelection = sender as Picker;
            TrailText.Text = PickerSelection.SelectedItem.ToString();
        }

并希望仅向用户显示值,但向程序返回键

public List<KeyValuePair<int, string>> GPXList_PickerItems { get; set; }
vaqhlq81

vaqhlq811#

正如Jason所说,使用ItemDisplayBinding
第一个

相关问题