OnPropertyChanged with a List

后端 未结 1 1235
天涯浪人
天涯浪人 2020-12-22 09:07

I have a data grid in a view that is bound to a List in a viewmodel. I have a lot of data to retrieve for the list, so I want to break it up into many small retrievals inst

相关标签:
1条回答
  • 2020-12-22 09:56

    Have you tried using an ObservableCollection<T> rather than a List<T>

    I assume you have a public property called Cars similar to...

    public List<Car> Cars{
    
       get { return this._cars;}
       set
       {
          this._cars = value;
          base.OnPropertyChanged("Cars");
       }
    
    }
    

    If not this will not actually do anything...base.OnPropertyChanged("Cars");

    Extension Method AddRange for ObservableCollection

    public static class Extensions
    {
        public static void AddRange(this ObservableCollection obj, List<T> items)
        {
            foreach (var item in items)
              obj.Add(item);
        }
    }
    
    0 讨论(0)
提交回复
热议问题