【发布时间】:2017-02-03 08:20:50
【问题描述】:
我需要更新原生 ListView 中的项目数据。
1.使用 Xamarin.Forms ListView。 简单的DataItem 模型与INotifyPropertyChanged:
List<DataItem> Data = new List<DataItem>();
// ... fill Data
ListView listDevice = new ListView();
listDevice.ItemsSource = Data;
listDevice.ItemTemplate = new DataTemplate(typeof(DataView));
...
void BtnTest_Clicked(object sender, EventArgs e)
{
Data[0].DeviceName = "Update OK";
}
当点击 btnTest 时,我立即在第一个 ListView 元素中看到“更新确定”。一切都很好。
2。使用 ListView 的渲染器。 我使用 WorkingWithListviewNative 示例,它有渲染器和适配器。我将DataSource2 替换为DataItem 模型(无处不在)并添加相同的btnTest。带有数据的列表是可见的,但是当单击按钮时没有任何变化。向下和向上滚动后,我看到了变化。
我需要将哪些代码添加到渲染器(添加到 OnElementPropertyChanged?)或适配器?
【问题讨论】:
标签: android forms listview xamarin renderer