首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向ListBox - WFP - C#动态添加按钮

如何向ListBox - WFP - C#动态添加按钮
EN

Stack Overflow用户
提问于 2013-09-11 07:48:07
回答 1查看 1.6K关注 0票数 0

我希望在ListBox的末尾通过按钮动态添加按钮以动态添加ListBox。

我想要有按钮的ListBox,每个按钮都有不同的索引。因为在那之后我必须把事件放到那个按钮上。所以按钮将带有索引。

在“创建的ListBox将是按钮”下,单击后可以添加带有按钮的新ListBox (与第一个示例相同)。

我怎么能这么做?

谢谢你帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-12 07:12:42

以下是解决办法:

代码语言:javascript
复制
private Boolean addNewListBox(ListBox targetElement, int indexOfElement)
    {
        ListBox elementListBox = new ListBox();

        elementListBox.Name = "elementListBox" + indexOfElement;
        elementListBox.VerticalAlignment = VerticalAlignment.Top;

        targetElement.Items.Remove(addFloor);
        targetElement.Items.Add(elementListBox);
        elementListBox.Items.Add(putElements("TEST", index));
        targetElement.Items.Add(addFloor);
        return true;
    }
public object putElements(string nameOfElement, int indexOfElement)
    {
        if (nameOfElement.Contains("TEST"))
        {
            Button floorButton = new Button();

            floorButton.Name = "floorButton" + indexOfElement;
            floorButton.Content = "floorButton" + indexOfElement;
            floorButton.Height = 60;
            floorButton.Width = 87;
            floorButton.Margin = new Thickness(0, 2, 0, 0);

            return floorButton;
        }
    }

当然有按钮上的事件。;)

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18735476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档