I'm building an app with Xamarin forms and i wanted to use the IncrementalListView
I've seen these 2 implementations 1 and 2 but none seems to work properly so i mixed both to be able to run my code.
The problem now is that nothing is being displayed on the View.
Here is my code:
ImovsPage.cs
public partial class ImovsPage : ContentPage
{
public Task Initialization { get; private set; }
public static LinkedList<Imovel> Imoveis { get; set; }
public ImovsPage()
{
Initialization = InitializeAsync();
InitializeComponent();
}
async Task InitializeAsync()
{
Imoveis = await Imovel.GetInitializedListAsync();
}
}
ImovsPage.cs.xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:plugin="clr-namespace:IncrementalListView.FormsPlugin;assembly=IncrementalListView.FormsPlugin"
x:Class="YmoApp.ImovsPage">
<ContentPage.Content>
<plugin:IncrementalListView
ItemsSource="{Binding Imoveis}"
PreloadCount="5">
<x:Arguments>
<ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy>
</x:Arguments>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Image Source="{Binding Imagens}"/>
<Label Text="{Binding Valor}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<ActivityIndicator Margin="20" IsRunning="{Binding IsLoadingIncrementally}" IsVisible="{Binding IsLoadingIncrementally}"/>
</ListView.Footer>
</plugin:IncrementalListView>
</ContentPage.Content>
</ContentPage>
View Model
public class IncrementalViewModel : INotifyPropertyChanged, ISupportIncrementalLoading
{
public int PageSize { get; set; } = Settings.MaxImoveis;
public ICommand LoadMoreItemsCommand { get; set; }
public bool IsLoadingIncrementally { get; set; }
public bool HasMoreItems { get; set; }
public IncrementalViewModel()
{
LoadMoreItemsCommand = new Command(async () => await LoadMoreItems());
}
public event PropertyChangedEventHandler PropertyChanged;
async Task LoadMoreItems()
{
IsLoadingIncrementally = true;
Settings.incrementPage();
// Download data from a service, etc.
// Add the newly download data to a collection
foreach(Imovel imovel in await Imovel.GetInitializedListAsync()){
ImovsPage.Imoveis.AddLast(imovel);
}
HasMoreItems = (ImovListRequest.Total < Settings.Page * Settings.MaxImoveis);
IsLoadingIncrementally = false;
}
}
This is answered on the github issue