ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)

前端 未结 18 2700
一生所求
一生所求 2020-11-22 02:06

Does anyone know why this code doesn\'t work:

public class CollectionViewModel : ViewModelBase {  
    public ObservableCollection Con         


        
18条回答
  •  误落风尘
    2020-11-22 02:51

    I used Jack Kenyons answer to implement my own OC, but I'd like to point out one change i had to make to make it work. Instead of:

        if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            foreach(T item in e.NewItems)
            {
                //Removed items
                item.PropertyChanged -= EntityViewModelPropertyChanged;
            }
        }
    

    I used this:

        if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            foreach(T item in e.OldItems)
            {
                //Removed items
                item.PropertyChanged -= EntityViewModelPropertyChanged;
            }
        }
    

    It seems that the "e.NewItems" produces null if action is .Remove.

提交回复
热议问题