1

我的目标是实时更新记录列表视图。

在我设置的加载页面中:

List<Myobjetcs> myitems = new List<Myobjects>();

...
...
        listView.IsVisible = false;
        listView.RowHeight = 55;
        listView.IsPullToRefreshEnabled = true;
        listView.Refreshing += ListView_Refreshing;
        listView.ItemTapped += ListView_ItemTapped;
        listView.SeparatorVisibility = SeparatorVisibility.None;
        listView.SeparatorColor = Color.Black;
        listView.ItemsSource = myitems;

每 10 秒(使用 API)他们将随机更新数据,只有几条记录。我的目标是在不刷新列表视图的情况下更新项目......并且不将 ItemSource 设置为 null 然后重新分配数据。

 public async void setSuperficie()
 {
      //here i receive the result of API (every 10 seconds) and update record listview. 
 }

我尝试使用 for 循环滑动 ItemSource 并更新数据,但不起作用。

有可能吗?

listView.ItemsSource[index].Property = Value;
4

1 回答 1

1

什么是“我的物品”?

你必须使用 ObservableCollection

ObservableCollection<MyModel> myitems = new ObservableCollection<MyModel>();

然后

 public async void setSuperficie()
 {
      //here i receive the result of API (every 10 seconds) and update record listview. 
      // here you have to modify the myitems collection, adding or removing items
      myitems.add(mynewitem);
 }

您还应该实施 INotifyPropertyChanged。为此,我建议使用Fody

于 2017-03-17T09:47:13.390 回答