[英]How do I dynamically create multiple controls in Silverlight?
I know how to create a list of Controls and add new instances of them to it: 我知道如何创建控件列表并向其中添加新的实例:
private List<FirstCircleControl> Circles = new List<FirstCircleControl>();
FirstCircleControl mc = new FirstCircleControl();
Circles.Add(mc);
I want to add a whole bunch of "FirstCircleControls". 我想添加一大堆“ FirstCircleControls”。 How would I add 10 controls to my list?
如何将10个控件添加到列表中? I want to be able to "create" and then "add" them to the list using a loop.
我希望能够使用循环将它们“创建”然后“添加”到列表中。
I wonder why you might need to create them all at once and then add them to the list, but here's a solution: 我想知道为什么您可能需要一次全部创建它们,然后将它们添加到列表中,但这是一个解决方案:
Enumerable.Range(0, 10)
.Select(x => new FirstCircleControl())
.ToList() // Forces creation of controls.
.ForEach(x => Circles.Add(x)); // Adds them to the list.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.