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));
}
}