xamarin.forms - viewList itemSource 中的 System.NullReferenceException
问题描述
按照本教程:https ://docs.microsoft.com/pl-pl/xamarin/xamarin-forms/user-interface/listview/data-and-databinding
我得到了这个例外:
System.NullReferenceException:“对象引用未设置为对象的实例。”
在行:CategoryListView.ItemsSource = _category;
在教程中有一个警告,我猜这与我的问题有关,但我仍然不知道如何解决这个问题(我不完全理解警告)
命名空间 EduApp { [XamlCompilation(XamlCompilationOptions.Compile)] 公共部分类 QUIZListViewPage : ContentPage
{
ObservableCollection<Category> _category = new ObservableCollection<Category>();
//public ObservableCollection<Category> _Category { get { return _category; } }
public QUIZListViewPage()
{
CategoryListView.ItemsSource = _category;
_category.Add(new Category { categoryName = "first" });
InitializeComponent();
}
}
}
高级 C 中的 TY:
解决方案
推荐阅读
- javascript - object-fit: cover; stops working on dynamically added (Safari bug?)
- javascript - 替换字符、反斜杠和双引号注意完全工作
- python - 无法使用前端 dockerfile.v0 解决;服务“nginx”未能构建
- swift - 在 NSManagedObject 类上具有 fetchRequest 功能的原因是什么
- android - Xamarin Forms - 如果手动终止应用程序,如何拦截 Android 应用程序
- rust - 一个简单的测试用例来检查我对生锈寿命的理解
- kubernetes - Apache 地图集 关于 kubernetes
- javascript - 居中对齐 div 内的所有 p 标签
- sql - 哪个更有效,联合一个总和或总和一个联合
- bash - Bash:在循环的每次迭代中将时间的标准错误输出到新文件