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

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

    Simple solution for standard observablecollection that I've used:

    DO NOT ADD to your property OR CHANGE it's inner items DIRECTLY, instead, create some temp collection like this

    ObservableCollection tmpList= new ObservableCollection();
    

    and add items or make changes to tmpList,

    tmpList.Add(new EntityViewModel(){IsRowChecked=false}); //Example
    tmpList[0].IsRowChecked= true; //Example
    ...
    

    then pass it to your actual property by assignment.

    ContentList=tmpList;
    

    this will change whole property which causes notice the INotifyPropertyChanged as you need.

提交回复
热议问题