如何在没有多个的情况下添加到已创建的 StackLayout:Children.Add?
How to add to an already created StackLayout without multiple: Children.Add?
有没有一种方法可以添加到已创建的 StackLayout
而无需调用多个 Children.Add
?
这是已创建的代码:
public class Test1
{
public StackLayout contentStack;
public PopupDialog()
{
contentStack = new StackLayout()
{
Spacing = 0,
Padding = new Thickness(0),
Orientation = StackOrientation.Vertical,
};
contentStack.Children.Add(new Label() { Text = "Test1" });
contentStack.Children.Add(new Label() { Text = "Test2" });
contentStack.Children.Add(new Label() { Text = "Test3" });
};
请注意,对于这个问题,我不想在新的 Stacklayout() { }
的 { }
内添加
一切取决于:
如果您已经有一个collection,您可以做类似
的事情
public class Test1
{
List<Label> list = new List<Label>()
{
new Label() { Text = "Test1" },
new Label() { Text = "Test2" },
new Label() { Text = "Test3" },
};
public StackLayout contentStack;
public PopupDialog()
{
contentStack = new StackLayout()
{
Spacing = 0,
Padding = new Thickness(0),
Orientation = StackOrientation.Vertical,
};
foreach(var item in list)
contentStack.Children.Add(item);
};
除此之外,我不相信你能...
有没有一种方法可以添加到已创建的 StackLayout
而无需调用多个 Children.Add
?
这是已创建的代码:
public class Test1
{
public StackLayout contentStack;
public PopupDialog()
{
contentStack = new StackLayout()
{
Spacing = 0,
Padding = new Thickness(0),
Orientation = StackOrientation.Vertical,
};
contentStack.Children.Add(new Label() { Text = "Test1" });
contentStack.Children.Add(new Label() { Text = "Test2" });
contentStack.Children.Add(new Label() { Text = "Test3" });
};
请注意,对于这个问题,我不想在新的 Stacklayout() { }
{ }
内添加
一切取决于:
如果您已经有一个collection,您可以做类似
的事情public class Test1
{
List<Label> list = new List<Label>()
{
new Label() { Text = "Test1" },
new Label() { Text = "Test2" },
new Label() { Text = "Test3" },
};
public StackLayout contentStack;
public PopupDialog()
{
contentStack = new StackLayout()
{
Spacing = 0,
Padding = new Thickness(0),
Orientation = StackOrientation.Vertical,
};
foreach(var item in list)
contentStack.Children.Add(item);
};
除此之外,我不相信你能...