我需要更新本机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元素中看到"Update“。一切都很好。
2.为ListView使用渲染器。 Im使用WorkingWithListviewNative示例,它有渲染器和适配器。Im将DataSource2替换为DataItem模型(无处不在),并添加相同的btnTest。“带有数据的列表”是可见的,但当按钮单击时,没有任何更改。我看到了向下滚动和向上滚动后的变化。
我需要向渲染器(OnElementPropertyChanged)添加哪些代码?还是转接器?
发布于 2017-02-05 21:53:02
使用ObservableCollection代替List,并且在它处理属性更改通知时不需要执行属性更改通知。
https://stackoverflow.com/questions/42019711
复制相似问题