【发布时间】:2017-02-12 18:11:12
【问题描述】:
我在屏幕上有一个按钮,当我按下按钮时,我希望一个选择器显示有一个项目列表,并且选择项目时按钮的文本应该改变,选择器应该消失。
这是我的代码:
Picker picker = new Picker
{
Title = "What's in the slot?",
VerticalOptions = LayoutOptions.CenterAndExpand
//HorizontalOptions = LayoutOptions.Center
};
以及按下按钮时调用的函数:
private void Displaypickerview(int row, int column)
{
if (status == "filling board")
{
foreach (string text in pickerText)
{
picker.Items.Add(text);
}
foreach (string ore in oreLevels)
{
picker.Items.Add(ore);
}
picker.SelectedIndexChanged += (sender, args) =>
{
if (picker.SelectedIndex == -1)
{
}
else
{
//change value of cell and button
Picker picker = (Picker)sender;
int index = picker.SelectedIndex;
if (index < pickerText.Length)
{
board[row, column].Text = pickerText[index - 1];
}
else {
board[row, column].Text = oreLevels[index - 1 - pickerText.Length];
}
}
};
}
else if (status == "choosing item")
{
}
}
但我不知道我应该如何在屏幕上呈现选择器视图并在之后将其删除。
更新:
下图中完成按钮的事件处理函数是什么。
【问题讨论】:
标签: c# xamarin xamarin.forms picker