0

我有列表框(在后面的代码中添加),我想在 Items.Count > 4 时设置最后一项的可见性。我有一个充满按钮的列表框。

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

错误在哪里?

4

1 回答 1

0

我发现了我的错误:

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

mainCycle(list);

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

        if (itemCounts >= 4)
        {
            MessageBox.Show("" + previousButton.Name);
            previousButton.Visibility = Visibility.Collapsed;
        }
于 2013-10-07T08:13:04.817 回答