OnPropertyChanged with a List

后端 未结 1 1253
天涯浪人
天涯浪人 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 rather than a List

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

    public List 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 items)
        {
            foreach (var item in items)
              obj.Add(item);
        }
    }
    

    0 讨论(0)
提交回复
热议问题