2014-10-10 34 views
0

我已經收集了我的每個客戶的所有信息,並希望在我的初始視圖listView中填充CustomerID信息。不過,我認爲我處於對象的頂層,我不知道如何在我的listView上獲取CustomerID信息。ListView對象並將數據傳遞到Xamarin表單中的下一個視圖

此外我想將選定的物品信息傳遞到下一個視圖來顯示剩餘的相應客戶信息。

private IEnumerable <IDictionary<string,object>> myData; 
List <Customer> list= new List<Customer>(); 
var listView= new ListView(); 

foreach (var customers in myData) { 
    list.Add(new Customer((string)customers["CustomerID"], 
       (string)customers ["CompanyName"], 
       (string)customers ["ContactName"], 
       (string)customers ["ContactTitle"], 
       (string)customers ["Address"], 
       (string)customers ["Region"], 
       (string)customers ["PostalCode"], 
       (string)customers ["City"], 
       (string)customers ["Fax"], 
       (string)customers ["Phone"] 
    )); 

} 
listView.ItemsSource=list; 

SearchBar searchBar = new SearchBar 
{ 
    Placeholder = "Xamarin.Forms Property", 
}; 

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

listView.ItemSelected += (sender, e) => { 
    //my next view is DetailPage 
}; 

enter image description here

回答

1

的ItemsSource是對象的集合。

您將需要創建一個的ItemTemplate然後將用於爲每個項目這個集合內進行渲染。

在這個的ItemTemplate您可以添加各種Xamarin.Forms細胞,看到here,或者從派生ViewCell創建自己的佈局。

有一個的ListView使用自定義類here的教程,實現頁面的結束,這將是在這兩個代碼隱藏XAML方法相當有用的給你。

它還顯示如何獲取選定的值並將其傳遞到另一個頁面,方法是查看listView.SelectedItem中的選定值並將其轉換爲模型。

+0

http://stackoverflow.com/questions/26407176/odata-hangs-forever-in-xamarin-form – casillas 2014-10-16 14:46:47

相關問題