我正在以xamarin形式使用Picker。我将下面的类绑定到Picker:
public string FieldCode{get; set; }
public string FieldValue{get; set; }
选择器如下:
<Picker Grid.Row="1" Grid.Column="0" x:Name="pkrMvmtCat" Style="{StaticResource WOFormPicker}" Title="Select" ItemsSource="{Binding FieldCode}" ItemDisplayBinding="{Binding FieldValue}" SelectedIndexChanged="pkrMvmtCat_SelectedIndexChanged"></Picker>
当我更改选择器索引时,我想获取FieldCode值。
请我解决此问题。
答案 0 :(得分:0)
您必须先听事件,然后从列表中投射选定的项目。这是一个示例:
void OnPickerSelectedIndexChanged(object sender, EventArgs e)
{
var picker = (Picker)sender;
int selectedIndex = picker.SelectedIndex;
if (selectedIndex != -1)
{
var field = (string)picker.ItemsSource[selectedIndex];
}
}