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

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

    Simple solution in 2 lines of code. Just use the copy constructor. No need to write TrulyObservableCollection etc.

    Example:

            speakers.list[0].Status = "offline";
            speakers.list[0] = new Speaker(speakers.list[0]);
    

    Another method without copy constructor. You can use serialization.

            speakers.list[0].Status = "offline";
            //speakers.list[0] = new Speaker(speakers.list[0]);
            var tmp  = JsonConvert.SerializeObject(speakers.list[0]);
            var tmp2 = JsonConvert.DeserializeObject(tmp);
            speakers.list[0] = tmp2;
    

提交回复
热议问题