0
votes

i have the code:

    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;

I want show in a label the text it's in block.content with title "hp-int" but appears the error "Cannot implicitly convert type 'System.Collections.Generic.IEnumerable to string". if i choose the title works fine, but the content...

Can help me?? thanks

1
How does the Block class look like? What is the type of the Content property? What does it contain? - Yacoub Massad
the block like: public IEnumerable<Block> Blocks { get; set; } (block.Content as List<string>).Add(item.Groups["blockContent"].Value.Trim()); i just want show the content when the title is "some tag"; when layout.children.add (new Label(){Text=block.Content}); show the error... - Pedro Silva

1 Answers

0
votes

If the Content property is a list of strings, then you have to combine them in one string, e.g.

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

As suggested by @Charles Mager this would perform better:

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