我正在用Xamarin表单构建一个应用程序,我想使用
IncrementalListView
我看过这两个实现
1
和
2
但似乎没有一个能正常工作,所以我混合了这两个功能,以便能够运行我的代码。
现在的问题是视图上没有显示任何内容。
这是我的代码:
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>
视图模型
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;
}
}