Hi UniversalCoder12-1951,
Welcome to our Microsoft Q&A platform!
Which control do you use to display contact information? ListView or CollectionView?
If you are using ColectionView, You can set RemainingItemsThreshold
and RemainingItemsThresholdReachedCommand
to load data incrementally.
For more info, you can refer to Load data incrementally.
And here is a simple demo you can refer to.
CollectionView.xaml
<CollectionView
VerticalScrollBarVisibility="Always"
ItemsSource="{Binding ContactToDisplay}"
RemainingItemsThreshold="10"
RemainingItemsThresholdReachedCommand="{Binding LoadContactCommand}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame>
<StackLayout>
<Label Text="{Binding Name}"/>
<Label Text="{Binding Number}"/>
<Label Text="{Binding Location}"/>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
ContactViewModel.cs
class ContactViewModel : BaseViewModel
{
public Command LoadContactCommand { get; set; }
public ContactViewModel()
{
LoadContactCommand = new Command(LoadContact);
InitContact();
}
int startIndex = 1;
// add 10 contacts once
int showOnScreenCount = 10;
private void LoadContact()
{
// add new item to ContactToDisplay
ContactToDisplay.AddRange(
AllContacts.Skip(showOnScreenCount * startIndex).Take(showOnScreenCount)
);
startIndex++;
}
public List<Person> AllContacts { get; set; }
ObservableRangeCollection<Person> contactToDisplay;
public ObservableRangeCollection<Person> ContactToDisplay
{
get => contactToDisplay;
set => SetProperty(ref contactToDisplay, value);
}
private void InitContact()
{
AllContacts = new List<Person>();
for (var i = 1; i <= 1000; i++)
{
AllContacts.Add(new Person
{
Name = "NAME" + i.ToString(),
Number = "NUMBER" + i.ToString(),
Location = "LOCATION" + i.ToString()
}); ;
}
contactToDisplay = new ObservableRangeCollection<Person>(AllContacts.Take(showOnScreenCount).ToList());
}
}
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.