我希望在ListBox的末尾通过按钮动态添加按钮以动态添加ListBox。
我想要有按钮的ListBox,每个按钮都有不同的索引。因为在那之后我必须把事件放到那个按钮上。所以按钮将带有索引。
在“创建的ListBox将是按钮”下,单击后可以添加带有按钮的新ListBox (与第一个示例相同)。
我怎么能这么做?
谢谢你帮忙!
发布于 2013-09-12 07:12:42
以下是解决办法:
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;
}
}当然有按钮上的事件。;)
https://stackoverflow.com/questions/18735476
复制相似问题