我可以在Xamarin.Forms中结合元素的创建和添加新元素吗?

时间:2018-08-13 07:53:06

标签: xamarin xamarin.forms

我有此代码:

var layout = new StackLayout
{
    Orientation = StackOrientation.Vertical,
    Spacing = 0
};
layout.Children.Add(new HeaderTemplate
{
    Header = Settings.cc.LongText().ToUpper()
});

这两个语句可以以某种方式组合吗?

1 个答案:

答案 0 :(得分:2)

尝试一下。

var layout = new StackLayout
{
    Orientation = StackOrientation.Vertical,
    Spacing = 0,
    Children = 
    {
        new HeaderTemplate
        {
            Header = Settings.cc.LongText().ToUpper()
        }
    }
};