<syncfusion:SfListView x:Name="listView"
ItemSize="100"
SelectionMode="Single"
SelectionGesture="Tap"
SelectionBackgroundColor="#E4E4E4"
IsStickyHeader="true"
Grid.Row="1"
ItemsSource="{Binding PagedSource, Source={x:Reference dataPager}}">
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.4*" />
<RowDefinition Height="0.3*" />
</Grid.RowDefinitions>
<Label Text="{Binding Number}" FontAttributes="Bold" TextColor="Teal" FontSize="21" />
<Label Grid.Row="1" Text="{Binding EstimatedValue}" TextColor="Teal" FontSize="15"/>
</Grid>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>
<sfPager:SfDataPager x:Name="dataPager"
UseOnDemandPaging="True"
DisplayMode = "PreviousNextNumeric"
NumericButtonCount = "4"
HorizontalOptions="Center"
Grid.Row="2"
PageCount="60" />
public class SfListViewPagingBehavior : Behavior
{
private Syncfusion.ListView.XForms.SfListView listView;
private RequisitionListViewModel viewModel;
private SfDataPager dataPager;
private IList Items { get; set; }
public IFinanceRestService FinanceRestService => DependencyService.Get() ?? new FinanceRestService();
public SfListViewPagingBehavior()
{
Items = new ObservableCollection();
}
protected override void OnAttachedTo(ContentPage bindable)
{
listView = bindable.FindByName("listView");
dataPager = bindable.FindByName("dataPager");
viewModel = new RequisitionListViewModel();
dataPager.OnDemandLoading += DataPager_OnDemandLoading;
base.OnAttachedTo(bindable);
}
private void DataPager_OnDemandLoading(object sender, OnDemandLoadingEventArgs e)
{
try
{
AsyncUtil.RunSync(() => ExecuteLoadItemsAsync(e.StartIndex));
var items = this.Items.AsEnumerable();
dataPager.LoadDynamicItems(e.StartIndex, items);
}
catch(Exception ex)
{
}
}
public async Task ExecuteLoadItemsAsync(int pageIndex)
{
try
{
Items.Clear();
var searchResult = await this.FinanceRestService.GetRequisitions();
foreach (var item in searchResult.SearchResults)
{
Items.Add(item);
}
}
catch (Exception ex)
{
await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
Debug.WriteLine(ex);
}
}
protected override void OnDetachingFrom(ContentPage bindable)
{
listView = null;
viewModel = null;
dataPager = null;
base.OnDetachingFrom(bindable);
}
}