StackLayout:无法分配子属性

时间:2017-08-06 14:05:16

标签: c# xamarin xamarin.forms

我在Xamarin.Forms中有这段简单的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace ReflectedColors
{
    public class ColorBlocksPage : ContentPage
    {
        public ColorBlocksPage()
        {
            Content = new StackLayout
            {

            };
        }
    }
}

我点击了c成员初始值设定项中的StackLayout,以便设置Children集合,我得到:

enter image description here

尽可能Children不存在。

如果我试着写

Content = new StackLayout
{
    Children = new Label { Text = "Test"}
};

尝试构建解决方案时出现以下错误:

  

错误CS0200属性或索引器' Layout.Children'不可能是   分配给 - 它是只读的

我必须做一些愚蠢的事情,但遗憾的是不知道这个问题可能是什么原因。

1 个答案:

答案 0 :(得分:2)

您正在将Children属性分配给新标签 设置子属性的正确方法:

Content = new StackLayout
{
    Children = {new Label { Text = "Test"}}
};
相关问题