【问题标题】:Pass list to Section within RootElement c#将列表传递给 RootElement c# 中的部分
【发布时间】:2016-01-07 09:50:05
【问题描述】:

我正在向 RootElement 的一部分添加某些值,如下所示:-

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"),

     },

现在,StringElements 是硬编码的。我想将从 API 调用中获取的字符串列表传递给该部分。该列表将是动态的。如何传递此列表以使用列表中的字符串值创建项目部分?

感谢任何帮助。

【问题讨论】:

    标签: c# ios list xamarin sections


    【解决方案1】:

    如果你有一个字符串数组,你可以使用 Linq 试试这个:-

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

    【讨论】:

      【解决方案2】:
      var section = new Section("Pages");
      
      foreach(var s in MyListOfStrings) {
        section.Add(new StringElement(s));
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-03
        • 2012-08-23
        • 2015-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多