无法将类型&System; Series.Collections.Generic.IEnumerable <string>隐式转换为字符串

时间:2016-05-21 10:57:42

标签: c# layout label

我有代码:

    public HomePage1()
    {
        InitializeComponent();
        LoadExcelFile loader = new LoadExcelFile();
        loader.ReadAndParse();            
        Title = "Home Page";
        StackLayout layout = new StackLayout();
        layout.Children.Add(new Image() { Source = "@drawable/img" });


        foreach (Block block in loader.Blocks)
        {
            switch (block.Title.ToLower())
            {
                case "hp-int":                        
                    layout.Children.Add(new Label(){Text=**block.Content**});
                    break;
                default:
                    //layout.Children.Add(new Label() { Text = block.Content });
                    break;
            }


        }

        Content = layout;

我希望在标签中显示它在block.content中带有标题&#34; hp-int&#34;的文本。但出现错误&#34;无法隐式转换类型&#39; System.Collections.Generic.IEnumerable到字符串&#34;。 如果我选择标题工作正常,但内容......

可以帮帮我吗?感谢

1 个答案:

答案 0 :(得分:0)

如果Content属性是字符串列表,则必须将它们组合在一个字符串中,例如

layout.Children.Add(new Label(){Text= block.Content.Aggregate((a, b) => a + b) }); 

根据@Charles Mager的建议,这会表现更好:

layout.Children.Add(new Label(){Text= string.Concat(block.Content) });