列表框的滚动事件

时间:2014-04-18 13:14:59

标签: json windows-phone-8 listbox

我已经打电话给json请求&它会在一次通话中给我20个项目。我在我的页面中设置了这20个项目,但实际上总项目是1000,现在我想再拨打20个数据&滚动后将它加载到同一页面中,以便我必须处理哪个scrollviewer事件,以便我将管理一个页面中的所有项目?

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>

2 个答案:

答案 0 :(得分:0)

ScrollViewer,它位于ListBox模板中,处理列表框的ValueChanged事件,一旦滚动开始就会发生。

答案 1 :(得分:0)

您可以提取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

相关问题