表单在ListView中显示文本,而不是typename
我正在用项目填充Xamarin.Forms.ListView表单在ListView中显示文本,而不是typename,listview,xamarin,xamarin.forms,Listview,Xamarin,Xamarin.forms,我正在用项目填充Xamarin.Forms.ListView public class LCIDEditor : ContentPage { private ListView _lv; private ObservableCollection<TextCell> _ItemList = new ObservableCollection<TextCell>(); public LCIDEditor() { this.Titl
public class LCIDEditor : ContentPage
{
private ListView _lv;
private ObservableCollection<TextCell> _ItemList = new ObservableCollection<TextCell>();
public LCIDEditor()
{
this.Title = "LCIDEditor";
_ItemList.Add(new TextCell { Text = "Englisch", Detail = "1033" });
_ItemList.Add(new TextCell { Text = "Deutsch", Detail = "1031" });
_lv = new ListView();
_lv.ItemsSource = _ItemList;
_lv.ItemTemplate = new DataTemplate(typeof(TextCell));
this.Content = _lv;
}
}
,我什么也看不到,列表视图保持空白
有人能告诉我我做错了什么吗?
我通读了这些文档,但它们没有什么帮助,我看到其他人也在问同样的问题,但在其他情况下也会问同样的问题
我正在尝试处理这个(显然不是这样)简单的例子。尝试以下方法:
public class LCIDEditor : ContentPage
{
private ListView _lv;
private ObservableCollection<object> _ItemList = new ObservableCollection<object>();
public LCIDEditor()
{
this.Title = "LCIDEditor";
_ItemList.Add(new { Text = "Englisch", Detail = "1033" });
_ItemList.Add(new { Text = "Deutsch", Detail = "1031" });
_lv = new ListView()
{
ItemTemplate = new DataTemplate(typeof(TextCell)),
ItemsSource = _ItemList
};
this.Content = _lv;
}
}
公共类LCIDEditor:ContentPage
{
私有列表视图_lv;
私有ObservableCollection_ItemList=新ObservableCollection();
公共LCIDEditor()
{
this.Title=“LCIDEditor”;
_添加(新的{Text=“Englisch”,Detail=“1033”});
_添加(新的{Text=“Deutsch”,Detail=“1031”});
_lv=新的ListView()
{
ItemTemplate=新数据模板(typeof(TextCell)),
ItemsSource=\u ItemList
};
this.Content=\u lv;
}
}
- TextCell必须像模板一样使用,而不是像项一样使用李>
- 当DataTemplate的ViewCell未绑定或对象的类型未被识别为有效项时,它将显示
结果-默认情况下的类型名称ToList()
我希望它对您有用从项目创建中删除
TextCell
。只需添加(新的{Text=“Englisch”,Detail=“1033”})并将其插入ItemTemplate set命令行之后。@Diegrafaelsouza谢谢,但由于各种原因,它不能以这种方式工作。你介意把全部代码都发出去吗?你说得对,对不起。这是因为可观察到的收集
。它必须是可观察的集合
。我会发布整个代码
public class LCIDEditor : ContentPage
{
private ListView _lv;
private ObservableCollection<object> _ItemList = new ObservableCollection<object>();
public LCIDEditor()
{
this.Title = "LCIDEditor";
_ItemList.Add(new { Text = "Englisch", Detail = "1033" });
_ItemList.Add(new { Text = "Deutsch", Detail = "1031" });
_lv = new ListView()
{
ItemTemplate = new DataTemplate(typeof(TextCell)),
ItemsSource = _ItemList
};
this.Content = _lv;
}
}