【发布时间】:2016-02-01 01:59:49
【问题描述】:
在我使用 Xamarin Forms 制作的 Xamarin 应用程序中,我收到错误消息“适配器的内容已更改,但 ListView 未收到通知。请确保您的适配器的内容未从后台线程修改,但仅来自 UI 线程。”。
我正在使用 Xamarin.Forms ListView 来显示学生列表。当我转到添加学生页面并将学生添加到列表中时,会引发此错误。
ListView listView = new ListView
{
ItemsSource = register.StudentList,
ItemTemplate = cell // Set the ImageCell to the item template for the listview
};
// Set the content for the page.
Content = new StackLayout
{
Children = { header, listView }
};
上面的代码来自注册页面,这里是显示学生列表的地方。下面的代码来自 AddStudent 页面,这是将学生添加到寄存器的地方。
//Now add the new student to the register.
if(register != null)
{
register.addStudent(Student);
}
//After adding to the register, open up the page for this register.
Navigation.InsertPageBefore(new RegisterPage(register), Navigation.NavigationStack.First());
await Navigation.PopToRootAsync();
我实际上并没有在代码中使用适配器,所以我不确定这个错误来自哪里。我见过的很多类似问题似乎都与 android 适配器有关,但这是一个用 Xamarin Forms 制作的应用程序。
在这种情况下是否可以使用某种替代方法?
【问题讨论】:
-
StudentList 的类型是什么?它是 ObservableCollection 吗?
-
它只是一个学生类型的列表。 Student 对象保存学生的姓名、ID 等数据。
标签: android listview xamarin xamarin.forms android-adapter