Search code examples
c#ioslistxamarinsections

Pass list to Section within RootElement c#


I am adding certain values to a section of RootElement like so:-

NavigationRoot = new RootElement("Menu"){ //Here we create the root of the elements
     new Section("Pages"){
      new StringElement ("Feed"),
      new StringElement ("Messages"),
      new StringElement ("Nearby"),
      new StringElement ("Events"),
      new StringElement ("Friends"),

     },

Right now, the StringElements are hard coded. I want to pass a List of strings which I fetch from an API call to the section. This list would be dynamic. How can I pass this list to create the section of items with the string values in the List?

Any help is appreciated.


Solution

  • You could try this using Linq if you have an Array of strings :-

    from page in myStringArray select new StringElement (page) as Element;