如何从列表中选择特定的课程项目?

时间:2017-07-07 01:58:40

标签: c# xamarin.forms

如何从列表中选择特定的课程项目?我想只在标签中绑定Name。

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.?)}
}

1 个答案:

答案 0 :(得分:3)

将现有的TextCell类型用于简单单元格

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