我有listBox(后面添加了代码),我想在Items.Count>时设置最后一项的可见性我的列表框里装满了按钮。
private void movingOfButtons(ListBox list, int index)
{
Control previousButton = (Control)list.Items.GetItemAt(list.Items.Count - 1);
int itemCounts = ktery.Items.Count;
indexButton = index;
// create new buttons
addNewButton("Sound");
addNewButton("addSound");
mainCycle(list);
// this does not work - it show only messageBox
if (itemCounts >= 4)
{
MessageBox.Show("" + previousButton.Name);
previousButton.Visibility = Visibility.Collapsed;
}
(list).Items.RemoveAt(index);
}
此previousButton.Visibility
不起作用。
错误在哪里?
答案 0 :(得分:0)
我发现了我的错误:
我必须“刷新”列表框中的项目..;)
mainCycle(list);
previousButton = (Control)list.Items.GetItemAt(list.Items.Count - 1);
if (itemCounts >= 4)
{
MessageBox.Show("" + previousButton.Name);
previousButton.Visibility = Visibility.Collapsed;
}