【问题标题】:Scrolling event of ListboxListbox的滚动事件
【发布时间】:2014-04-18 13:14:59
【问题描述】:

我已经调用了 json 请求,它会一次给我 20 个项目。我已经在我的页面中设置了这 20 个项目,但实际上总项目是 1000,现在我想调用另外 20 个数据并将其加载到同一页面之后滚动,所以我必须处理滚动查看器的哪个事件,以便我将管理一页中的所有项目?

ListBox 的样子:

<ListBox Name="lstSubNews" Grid.Row="1" SelectionChanged="lstSubNews_SelectionChanged" 
         ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource ListColor}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border Margin="5,0.8,5,0.8">
                <StackPanel Orientation="Vertical" Height="90" Width="500" Background="AliceBlue" >
                    <Grid >
                        <Grid.RowDefinitions >
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="420"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding subject}"Grid.Row="0" Grid.Column="0"></TextBlock>
                        <TextBlock Text="{Binding poster}" Grid.Row="1" Grid.Column="0" ></TextBlock>
                    </Grid>
                </StackPanel>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

【问题讨论】:

    标签: json windows-phone-8 listbox


    【解决方案1】:

    在 ListBox 模板中的 ScrollViewer,它处理滚动开始时发生的列表框的 ValueChanged 事件。

    【讨论】:

    • @Pradeep Kesharwani 如果你能举个例子?
    • @Viraj 在这里,我只是给你一个想法来解决你的问题,你有一个网络服务,它给你 20 个项目作为响应,而我没有这样的网络服务,这就是我无法申请的方式它为您演示
    【解决方案2】:

    您可以提取ScrollViewer,然后检测用户何时滚动到底部。

    var border = (VisualTreeHelper.GetChild(lstSubNews, 0) as Border);
    ScrollViewer scrollViewer = border.Child as ScrollViewer;
    
    scrollViewer.ViewChanged += async (a, t) =>
        {
            if (scrollViewer.VerticalOffset > scrollViewer.ScrollableHeight - 5)
            {
                //code here
            }
        };
    

    但是正确的做法是实现ISupportIncrementalLoading 接口: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.data.isupportincrementalloading

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 2021-05-12
      相关资源
      最近更新 更多