Search code examples
botframeworkmicrosoft-teamsadaptive-cards

Botframework Loop inside of AdaptiveCard C#


I want to create a loop in side adaptive card body for adaptivecardcontainer. I have refereed the below solution but issue is i have to add loop to container inside the body, so how to access the container to add my textblock code. C# Botframework Loop inside of AdaptiveCard I have to add for loop at below possition. enter image description here


Solution

  • You can create list of Adaptive TextBlocks first and then assign it at appropriate position.

                    var textBlocks = new List<AdaptiveElement>();
                    for (int i = 1; i < 5; i++)
                    {
                        textBlocks.Add(new AdaptiveTextBlock() { Text = "Textblock" + i });
                    }
    
                    var adaptiveCard = new AdaptiveCard("1.0")
                    {
                        Body = new List<AdaptiveElement>()
                        {
                            new AdaptiveContainer
                            {
                                Items=textBlocks
                            }
                        }
    
                    };