ObservableCollection 列表不更新 Xamarin 项目中的 Listview

ObservableCollection list does not update Listview in Xamarin project

我有一个 Xamarin 项目。我想用对象列表填充列表视图,列表视图必须在添加、更新或删除列表后自行刷新。我已经设法通过添加和更新来做到这一点,但是当我尝试删除时,Listview 不会刷新。我使用 INotifyPropertyChanged 基本模型继承自:

 public class BaseModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;


        protected bool SetProperty<T>(ref T storage, T value,
            [CallerMemberName] String propertyName = null)
        {
            if (object.Equals(storage, value)) return false;

            storage = value;
            this.OnPropertyChanged(propertyName);
            return true;
        }

        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var eventHandler = this.PropertyChanged;
            if (eventHandler != null)
            {
                eventHandler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }

ipsettings 模型:

public class IpSettingModel : BaseModel
    {
        public IpSettingModel(String ip)
        {
            this._ip = ip;            
        }

        private string _ip = string.Empty;        
        public string ip
        {
            get { return this._ip; }
            set { this.SetProperty(ref this._ip, value); }
        }
}

用适配器填充列表视图:

ObservableCollection<IpSettingModel> iplist = new ObservableCollection<IpSettingModel>();

    IpAdapter myadapter = new IpAdapter(this, iplist);
    ipListview.Adapter = myadapter;

到目前为止一切顺利。如果我添加或更新列表的对象,它工作正常。 当我尝试删除对象时

IpManageClass.datasource.Remove(IpManageClass.datasource.Where(o => o.ip == selecteditem.ip).Single());

对象已从 ObservableCollection 中删除,但 Listview 未刷新。我错过了什么?

我找到了解决方案。 我在适配器上添加了更新功能:

public void Update()
  {            
      NotifyDataSetChanged();
  }  

我在删除列表中的任何对象后调用此函数