简体   繁体   English

ListView WP8中的增量加载

[英]Incremental Loading in ListView WP8

I have read the articles about how to do incremental loading when we scroll to bottom of the list view, but how to achieve lazy loading when we scroll to top of the list. 我已经阅读了有关滚动至列表视图底部时如何进行增量加载的文章,但已阅读了有关滚动至列表顶部时如何实现延迟加载的文章。 I want to add more items to the top of the list when the user reaches the top. 我想在用户到达顶部时将更多项目添加到列表的顶部。 Is there any way we can achieve this. 有什么方法可以实现这一目标。

Found a solution for this. 找到了解决方案。 Rotate both controls. 旋转两个控件。

For eg-> 对于例如->

<ListView x:Name="GridViewMain" IncrementalLoadingThreshold="2" RenderTransformOrigin="0.5,0.5"> <ListView.RenderTransform> <RotateTransform Angle="180"></RotateTransform> </ListView.RenderTransform> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/> </Style> </ListView.ItemContainerStyle> <ListView.Resources> <DataTemplate x:Key="DataTemplateGridViewMain"> <Grid HorizontalAlignment="Stretch" Background="#FF7C1A9B" RenderTransformOrigin="0.5,0.5"> <Grid.RenderTransform> <RotateTransform Angle="180"/> </Grid.RenderTransform> <TextBlock HorizontalAlignment="Left" Text="{Binding}" VerticalAlignment="Center" FontSize="20" FontFamily="Tempus Sans ITC" /> </Grid> </DataTemplate> </ListView.Resources> <ListView.ItemTemplate> <StaticResource ResourceKey="DataTemplateGridViewMain" /> </ListView.ItemTemplate> </ListView>

Worked for me. 为我工作。

There is no built in solution. 没有内置的解决方案。

Here's an example that checks the ListViews scroll position and loads additional items once it is at the top. 这是一个检查ListViews滚动位置并在其位于顶部时加载其他项目的示例。

// Attach to the view changed event
_scrollViewer = listview.GetFirstDescendantOfType<ScrollViewer>();
if (_scrollViewer != null)
{
    _scrollViewer.ViewChanged += OnViewChanged;
}

And the handler. 和处理程序。

private void OnViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    // If scrollviewer is scrolled up
    if (_scrollViewer.VerticalOffset < 150)
    {
        // Start loading new items...
    }
}

Handle with care: 小心轻放:

When adding items at the top, scroll position will change. 在顶部添加项目时,滚动位置将改变。

The check is very simple, is will only work if the scrollviewer can actually scroll. 该检查非常简单,只有在scrollviewer可以实际滚动的情况下才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM