【问题标题】:Population of TableView Data in XamarinXamarin 中 TableView 数据的填充
【发布时间】:2014-10-09 09:06:21
【问题描述】:

我已成功从 URL 获取数据并将其分配给我的客户字典,并且我可以在输出中写入每个客户对象。但是,由于我是这个平台的新手,我无法在 TableView Cell 上填充数据。我已附上我的代码。

private IEnumerable <IDictionary<string,object>> Customers;
public MyDataServices ()
        {
            InitializeComponent ();
            InitializeDataService ();
            GetDataFromOdataService ();

            foreach (var customers in Customers){
                System.Diagnostics.Debug.WriteLine((string)customers["ContactName"]);
                // populate Data on TableView

            }

            Padding = new Thickness (10, 20, 10, 10);
            Content = new StackLayout () {
                Children = { tableView }

            };
}

【问题讨论】:

    标签: c# xamarin


    【解决方案1】:

    假设客户实例具有 ContactNameContactPosition 字段,这将创建带有这些详细信息的基本 TextCells 并将它们添加到表视图中。

    // create a TableSection to hold the cells
    var section = new TableSection("Customers");
    
    foreach (var customer in Customers){
        System.Diagnostics.Debug.WriteLine((string)customers["ContactName"]);
        // populate Data on TableView
        var name = (string)customer["ContactName"];
        var position = (string)customer["ContactPosition"]
    
        var cell = new TextCell { Text = name, Detail = position };
        section.Add(cell);
    }
    
    // add the section to the TableView root
    tableView.Root.Add(section);
    

    然后您像往常一样将TableView 添加到您的布局中。

    Xamarin 文档中有信息here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多