2
我在屏幕上有一個按鈕,當我按下按鈕時,我希望一個選擇器出現一個項目列表,當選擇一個項目時,按鈕的文本應該改變爲選取器應該消失。如何動態添加一個選擇器
這是我的代碼:
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")
{
}
}
但我不知道我應該如何呈現在選擇器視圖屏幕並在之後刪除它。
更新:
什麼是下圖中完成按鈕的事件處理程序。
Grid.SetRow(picker, 0); //first row
Grid.SetColumn(picker, 0); //first column
grid.Children.Add(picker);
同樣你從Children
集合中移除它刪除:
我有一個按鈕的網格,所以不會刪除按鈕上的按鈕e第一行和列 – Cing
Grid.SetRow/Grid.SetColumn方法設置元素的附加Grid.Row和Grid.Column屬性,即它指定元素(選取器)將位於網格中的哪一行和哪一列。並且您刪除傳遞給Remove方法的項目。 – mm8
按下完成按鈕時應調用remove函數,但完成按鈕的代碼是什麼? – Cing