Xamarin.Forms NotifyPropertyChanged不更新已经存在的项目Android

问题描述

我有一个这样的ListView:

        <ListView x:Name="ItemsListView"
                ItemsSource="{Binding Items}"
                VerticalOptions="FillAndExpand"
                HasUnevenRows="true"
                RefreshCommand="{Binding LoadItemsCommand}"
                IsPullToRefreshEnabled="False"
                IsRefreshing="{Binding IsBusy,Mode=OneWay}"
                CachingStrategy="RecycleElement"
                ItemSelected="OnItemSelected">

并且我的ViewModel具有此定义,并且我的Model类如下:

    public ObservableCollection<IncomingJobItem> Items { get; set; }
    public class IncomingJobItem
    {
        public int Index { get; set; }

        [JsonProperty("id")]
        public string Id { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("amount")]
        public int Amount { get; set; }
    }

现在,当我更新ViewModelObject.Items并调用NotifyPropertyChanged时,ListView中已经存在的项目不会得到更新。

示例:

// change already existing item
ViewModelObject.Items[0].Amount = 3;

// notify item in Items has changed
ViewModelObject.NotifyPropertyChanged("Items");

// nothing happens,item 0 in the list stays with the old amount...
// expected is to update the item in the list to display 3

但是,当我创建新元素并将其添加到ViewModelObject.Items时,ListView会添加新的Item,但不会更新现有的Item。我该怎么办?

ViewModelObject.NotifyPropertyChanged("Items.Amount");也不执行任何操作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)