I need to show very big data in a ListView. Must I load all the data once? My code is below:
using System.Collections.ObjectModel;
namespace Brunie.Mobile.ViewModels {
public class VmListCompany {
public ObservableCollection<Company> AllCompanies {
get;
} = new ObservableCollection<Company>();
public VmListCompany() {
LoadAllCompanies();
}
private void LoadAllCompanies() {
Company company = null;
while(null != (company = GetNextCompany(company))) {
AllCompanies.Add(company);
}
}
private bool HasNextCompany(Company company) {
bool hasNextCompany = false;
......
return (hasNextCompany);
}
private Company GetNextCompany(Company company) {
if(!HasNextCompany(company)) {
return (null);
}
Company nextCompany = new Company();
......
return (nextCompany);
}
}
public class Company {
public string Name {
get;
set;
}
public string Address {
get;
set;
}
public int NumberOfEmployees {
get;
set;
}
}
}
ListView in Xaml:
<ListView ItemsSource="{Binding AllCompanies}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Name}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
After called LoadAllCompanies the count of AllCompanies is 20562104. So my app is very slow now. How to handle this situation?