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

前端 未结 18 2705
一生所求
一生所求 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:50

    Just adding my 2 cents on this topic. Felt the TrulyObservableCollection required the two other constructors as found with ObservableCollection:

    public TrulyObservableCollection()
            : base()
        {
            HookupCollectionChangedEvent();
        }
    
        public TrulyObservableCollection(IEnumerable collection)
            : base(collection)
        {
            foreach (T item in collection)
                item.PropertyChanged += ItemPropertyChanged;
    
            HookupCollectionChangedEvent();
        }
    
        public TrulyObservableCollection(List list)
            : base(list)
        {
            list.ForEach(item => item.PropertyChanged += ItemPropertyChanged);
    
            HookupCollectionChangedEvent();
        }
    
        private void HookupCollectionChangedEvent()
        {
            CollectionChanged += new NotifyCollectionChangedEventHandler(TrulyObservableCollectionChanged);
        }
    

提交回复
热议问题