【问题标题】:StackLayout: Children property cannot be assigned toStackLayout:无法将子属性分配给
【发布时间】:2017-08-06 22:19:09
【问题描述】:

我在 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
            {

            };
        }
    }
}

我在StackLayout 成员初始化器中单击c 以设置Children 集合,然后我得到:

你可以Children不在那里。

如果我试着写

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

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

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

我一定是在做一些愚蠢的事情,但不幸的是,我不知道这个问题的根源是什么。

【问题讨论】:

标签: c# xamarin xamarin.forms


【解决方案1】:

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

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

【讨论】:

  • 我知道这很愚蠢!我仍然不明白为什么 IntelliSense 不显示该属性。
猜你喜欢
  • 2018-12-07
  • 2020-11-17
  • 2019-04-30
  • 1970-01-01
  • 1970-01-01
  • 2014-06-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多