Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
表单在ListView中显示文本,而不是typename_Listview_Xamarin_Xamarin.forms - Fatal编程技术网

表单在ListView中显示文本,而不是typename

表单在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

我正在用项目填充Xamarin.Forms.ListView

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;
    }
}