0

I have 2 classes, one a ViewModels that stores an ObservableCollection<T> dataSource and a method LoadMore() which adds 10 new items per request. The other class is xaml.cs to get the data from dataSource using LoadMore().

When I try to get new data using the code below it doesn't seem to update the Count property of dataSource, because it is always 10 items. I already tried using instance object and static class. How could I fix it?

ViewModels itemSource = new ViewModels();

itemSource.LoadMore(max_id);
if (itemSource.dataSource.Count == 100) // <=== .Count = 10
{
   //action
    max_id += 10;
}

itemSource.LoadMore(max_id);
if (itemSource.dataSource.Count == 100) // <=== Problem here .Count always 10, never growing up
{
   //action
}

Sample of ViewModels class like this

public class ViewModels
{
    public ObservableCollection<Model> dataSource{ get; private set; }
    public ViewModels()
    {
         dataSource= new ObservableCollection<Model>();
    }

    public void LoadMore(int max_id)
    {
        (Get.Data(max_id)).ForEach(d=> dataSource.Add(d));

    }
}
4

1 回答 1

-1

找到了,执行 itemSource.dataSource.Count 时 ObservableCollection.Add() 方法没有完成。现在修复。

于 2013-10-01T11:32:52.833 回答