WPF设置列表框中项目的可见性 - 代码隐藏

时间:2013-10-07 07:59:43

标签: c# wpf button listbox

我有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不起作用。

错误在哪里?

1 个答案:

答案 0 :(得分:0)

我发现了我的错误:

我必须“刷新”列表框中的项目..;)

mainCycle(list);

previousButton = (Control)list.Items.GetItemAt(list.Items.Count - 1);

        if (itemCounts >= 4)
        {
            MessageBox.Show("" + previousButton.Name);
            previousButton.Visibility = Visibility.Collapsed;
        }