在WindowsPhone8.1中实现分组ListView的LoadMore分页

本文关键字:ListView LoadMore 分页 WindowsPhone8 实现 | 更新日期: 2023-09-27 18:22:29

是否可以在分组的ListView(CollectionViewSource)中应用ListViewBase.LoadMoreItemsSync方法进行分页。或者你知道另一种方式,请告诉我。

在WindowsPhone8.1中实现分组ListView的LoadMore分页

您可以这样做:在您的ListView上添加"Loaded"事件,代码为:

 private void LvPictures_OnLoaded(object sender, RoutedEventArgs e)
 {
     ScrollViewer viewer = GetScrollViewer(this.LvPictures);
     viewer.ViewChanged += LvPictures_ViewChanged;
 }

public static ScrollViewer GetScrollViewer(DependencyObject depObj)
      {
          if (depObj is ScrollViewer) return depObj as ScrollViewer;
          for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
          {
              var child = VisualTreeHelper.GetChild(depObj, i);
              var result = GetScrollViewer(child);
              if (result != null) return result;
          }
          return null;
      }

现在,在ViewChangeEvent中,您可以指定何时加载更多项目,并实际执行以下操作:

     private async void LvPictures_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
      {
          ScrollViewer view = (ScrollViewer)sender;
          double progress = view.VerticalOffset / view.ScrollableHeight;
          if (progress > 0.8 & !_incallFilesList && NextPagePicturesAvailable)
          {
              _incallFilesList = true;
              GetNextPicturesPageAsync();
          }
          _incallFilesList = false;
      }