我有代码:
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中带有标题" hp-int"的文本。但出现错误"无法隐式转换类型' System.Collections.Generic.IEnumerable到字符串"。 如果我选择标题工作正常,但内容......
可以帮帮我吗?感谢
答案 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) });