2014-10-08 2 views
0

Я успешно извлек данные из URL-адреса и назначил их в словарь моих клиентов, и я смог написать каждый объект клиента на моем выходе. Однако, поскольку я совершенно новый на этой платформе, я не смог заполнить данные в CellView Cell. Я прикрепил свой код.Население данных TableView в Xamarin

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 } 

      }; 
} 

ответ

1

Предполагая, что экземпляры клиентов имеют ContactName и ContactPosition поля, это создает основные TextCell с с теми деталями, и добавляет их в виде таблицы.

// 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

+0

Большое спасибо nelposto. Он отлично работал. – casillas

+0

http://stackoverflow.com/questions/26303074/parsing-data-in-xamarin-forms – casillas

Смежные вопросы