我很难string
从我的选择器中取出所选的.这是我的代码:
XAML:
info1
info2
码:
thePicker.SelectedIndex = 1; //here is the problem i suppose, any idea what i should type?
var ourPickedItem = thePicker.Items[thePicker.SelectedIndex];
现在我只得到值"info1",即使我选择了数字2.这与SelectedIndex
它有关,所以它只选择"1",但我不知道如何编写代码使其适用于所选项目.
你应该看看这个:
picker.SelectedIndexChanged += (sender, args) =>
{
if (picker.SelectedIndex == -1)
{
boxView.Color = Color.Default;
}
else
{
string colorName = picker.Items[picker.SelectedIndex];
boxView.Color = nameToColor[colorName];
}
};
否则在新的Xamarin Forms Release 2.3.4中存在
可绑定的选择器
你可以设置一个ItemSource
并绑定SelectedIndex属性
SelectedIndex="{Binding CountriesSelectedIndex}"