2017-07-07 74 views
0

如何從列表中選擇特定的類項目?我只想綁定標籤中的名稱。如何從列表中選擇特定的課程項目?

mycountry.cs

public class mycountry{ 

private string Id; 
private string name; 
private string capital; 
private string majorcity; 


public string ID { get{return Id;} set{Id = value;}} 
public string Name { get{return name;} set{name = value;}} 
public string Capital { get{return capital;} set{capital = value;}} 
public string Majorcity { get{return majorcity;} set{majorcity = value;}} 
} 

mycountrypage.xaml.cs

List<mycountry> c; 
c = DB.GetCountry(); 

ListView list = new ListView{ 
ItemsSource = c, 
ItemTemplate = new DataTemplate(() =>{ 
Label name = new Label(); name.SetBinding(Label.TextProperty, c.?)} 
} 
+0

@mybirthname謝謝。現在我可以選擇名稱。 – batman

回答

3

使用現有TextCell類型簡單的細胞

list.ItemTemplate = new DataTemplate(typeof(TextCell)); 
list.ItemTemplate.SetBinding(TextCell.TextProperty, "Name"); 
+0

如果我在mycountry中有另一個稱爲private MyFlag標誌的屬性,該怎麼辦?我怎樣才能從該類中選擇項目。 list.ItemTemplate.SetBinding(TextCell.TextProperty,c.MyFlag。?); – batman

+0

TextCell還具有可以使用的DetailTextProperty,或者參考其他可綁定道具的文檔 – Jason

相關問題