Xaml 在windows phone 8.1应用程序中滚动列表框时,如何为列表框添加加载更多

Xaml 在windows phone 8.1应用程序中滚动列表框时,如何为列表框添加加载更多,xaml,c#-4.0,windows-phone-8.1,Xaml,C# 4.0,Windows Phone 8.1,当我们滚动时,如何显示5个项目?我想加载更多 <ListBox.ItemTemplate> <DataTemplate > <Border BorderThickness="0,0,0,1" BorderBrush="Black" HorizontalAlignment="Stretch" Width="400"

当我们滚动时,如何显示5个项目?我想加载更多

            <ListBox.ItemTemplate>
            <DataTemplate  >
                <Border BorderThickness="0,0,0,1" BorderBrush="Black" 
                        HorizontalAlignment="Stretch" Width="400" 
                        Margin="-8,0,-8,0">

                    <Grid Height="130" 
                          RenderTransformOrigin="0.37,0.52">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid HorizontalAlignment="Left" 
                                      Height="104" 
                                      Grid.Row="0"
                                         VerticalAlignment="Top" 
                                     Width="115" Background="White" 
                              Margin="05,-4,0,0">
                            <Image Source="{Binding company_logo}" Stretch="None" 
                                   Margin="10,0,0,0"/>
                        </Grid>
                        <Grid Height="104" HorizontalAlignment="Right"
                                        Grid.Row="0" 
                                        VerticalAlignment="Top" Width="280"
                                         Background="White" Grid.ColumnSpan="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="3*"/>
                                <ColumnDefinition Width="307*"/>
                            </Grid.ColumnDefinitions>

                            <TextBlock HorizontalAlignment="Left"
                                       Margin="0,0,0,0"
                                           TextWrapping="Wrap" 
                                       Text="{Binding product_name}"
                                           VerticalAlignment="Top" 
                                       FontSize="20" 
                                           Foreground="Orange" 
                                       Grid.Column="1"/>
                            <TextBlock Text="Reviews:" 
                                       Margin="97.5,27,125,51"                                           
                                       Grid.Column="1"/>
                            <TextBlock HorizontalAlignment="Left" 
                                       Margin="145,30,0,0"
                                           TextWrapping="Wrap"
                                       Text="{Binding product_reviews}"
                                           VerticalAlignment="Top" 
                                       FontSize="10" Width="50" 
                                           Foreground="Orange" 
                                       Grid.Column="1"/>
                            <TextBlock Text="Rating:" FontSize="15"
                                       Margin="0,25,232,51"
                                       Grid.Column="1"/>
                            <TextBlock HorizontalAlignment="Left" Margin="50,30,0,0"
                                           TextWrapping="Wrap" Text="{Binding product_rating}" 
                                           VerticalAlignment="Top" FontSize="10" 
                                           Foreground="Black" Grid.Column="1"/>
                            <Image Source="Assets/clock-icon.png" Margin="165,25,0,0" Width="25" Height="25"/>

                            <TextBlock Text="Created Date" FontSize="10"
                                       Margin="155,29,70,62" Foreground="Red"
                                       Grid.Column="1"/>

                            <TextBlock HorizontalAlignment="Left" Width="59"
                                                Margin="218,29,0,0"
                                                TextWrapping="Wrap" 
                                       Text="{Binding created_date}" 
                                                VerticalAlignment="Top" FontSize="10" 
                                                Foreground="Black"
                                                 Grid.Column="1" Height="13">
                            </TextBlock>

                            <TextBlock Text="Updated Date:" FontSize="10"
                                       Margin="155,39,70,52" Foreground="Red"
                                       Grid.Column="1"/>

                            <TextBlock HorizontalAlignment="Left" Width="59"
                                                Margin="218,39,0,0"
                                                TextWrapping="Wrap" 
                                       Text="{Binding updated_date}" 
                                                VerticalAlignment="Top" FontSize="10" 
                                                Foreground="Black"
                                                 Grid.Column="1" Height="13">
                            </TextBlock>

                            <TextBlock  HorizontalAlignment="Left" Margin="3,58,0,0" TextWrapping="Wrap" 
                                               Text="{Binding product_description}" 
                                               VerticalAlignment="Top"  FontSize="10"
                                               Foreground="Black"  Height="40" 
                                               Width="293" Grid.Column="1" />
                        </Grid>
                        <TextBlock HorizontalAlignment="Left" Margin="15,100,0,0" 
                                           TextWrapping="Wrap" Width="250"
                                   Text="{Binding companyName}" 
                                           VerticalAlignment="Top" FontSize="15" 
                                           Foreground="Black"/>
                        <Button Content="Contact" Foreground="Red"
                                FontSize="10" 
                                Margin="120,88,-29,440.667"
                               Height="25" Grid.Column="1"/>
                             </Grid>

                </Border>

            </DataTemplate>
        </ListBox.ItemTemplate>

    </ListBox>


下面是我的代码

List<products> products1 = new List<products>();
             try
             {
                 using (HttpClient client = new HttpClient())
                 {
                     client.BaseAddress = new Uri("something");
                     var url = "data/getProductsData";
                     Parameters product = new Parameters();
                     product.user_id = "1";                    
                     product.platform = "Android";                                        
                     string json = JsonConvert.SerializeObject(product);
                     StringContent queryString = new StringContent(json);
                     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                     HttpResponseMessage response = await client.PostAsync(url, queryString);

                     if (response.IsSuccessStatusCode)
                     {
                         var data = response.Content.ReadAsStringAsync();
                         Response my = JsonConvert.DeserializeObject<ResponseWrapper>(data.Result.ToString()).response;
                         LoadingBar.IsEnabled = true;
                         LoadingBar.Visibility = Visibility.Visible;
                         var myData =data.Result.ToString();
                         //await new MessageDiaglog("Data Loaded!").ShowAsync();
                         LoadingBar.IsEnabled = false;
                         LoadingBar.Visibility = Visibility.Collapsed;
                         foreach (var item in my.content.products)
                         {
                             products1.Add(item);                            
                          }
                     }
                     lstbox.ItemsSource = products1;

                 }
             }
                  catch (Exception ex)
            {
                MessageDialog message = new MessageDialog(ex.Message);
                message.ShowAsync();
List products1=新列表();
尝试
{
使用(HttpClient=new HttpClient())
{
client.BaseAddress=新Uri(“某物”);
var url=“数据/getProductsData”;
参数产品=新参数();
product.user_id=“1”;
product.platform=“Android”;
字符串json=JsonConvert.SerializeObject(产品);
StringContent queryString=新的StringContent(json);
client.DefaultRequestHeaders.Accept.Add(新的MediaTypeWithQualityHeaderValue(“应用程序/json”);
HttpResponseMessage response=wait client.PostAsync(url,queryString);
if(响应。IsSuccessStatusCode)
{
var data=response.Content.ReadAsStringAsync();
Response my=JsonConvert.DeserializeObject(data.Result.ToString()).Response;
LoadingBar.IsEnabled=true;
LoadingBar.Visibility=可见性.Visibility;
var myData=data.Result.ToString();
//等待新消息DiagLog(“数据已加载!”).ShowAsync();
LoadingBar.IsEnabled=false;
LoadingBar.Visibility=Visibility.collazed;
foreach(my.content.products中的var项)
{
产品1.添加(项目);
}
}
lstbox.ItemsSource=products1;
}
}
捕获(例外情况除外)
{
MessageDialog message=新建MessageDialog(例如message);
message.showsync();
首先:

1-更改此行

List<products> products1 = new List<products>();
4-在视图更改时

private  async void lstSoucrce_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            var sv = (ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.lstsource, 0), 0);
            var verticaloffset = sv.VerticalOffset;
            var maxVerticleOffset = sv.ScrollableHeight;

            if (maxVerticleOffset < 0 || verticaloffset == maxVerticleOffset)
            {
                 //this will fired up when you will reach end of list
                //load your more data here
            }
private async void lstsourcrce\u ViewChanged(对象发送方,ScrollViewServiceChangeDeventargs e)
{
var sv=(ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.lstsource,0),0);
var垂直偏移=sv垂直偏移;
var maxVerticleOffset=sv.ScrollableHeight;
如果(maxVerticleOffset<0 | | verticaloffset==maxVerticleOffset)
{
//当您到达列表的末尾时,这将被激发
//在此处加载更多数据
}

Hi price,如果您不介意,请将完整答案与我的代码一起编写代码。我比较新鲜。谢谢。我尝试过,但不适用于我。请将整个项目代码与我的代码共享。
public static ScrollViewer GetScrollViewer(DependencyObject dpj)
        {
            if (dpj is ScrollViewer) return dpj as ScrollViewer;
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dpj); i++)
            {
                var child = VisualTreeHelper.GetChild(dpj, i);
                var result = GetScrollViewer(child);
                if (result != null)
                {
                    return result;
                }

            }
            return null;
        }
 private void lstsource_Loaded(object sender, RoutedEventArgs e)
        {
            ScrollViewer viewer = GetScrollViewer(this.lstsource);
            viewer.ViewChanged += lstSoucrce_ViewChanged;
        }
private  async void lstSoucrce_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            var sv = (ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.lstsource, 0), 0);
            var verticaloffset = sv.VerticalOffset;
            var maxVerticleOffset = sv.ScrollableHeight;

            if (maxVerticleOffset < 0 || verticaloffset == maxVerticleOffset)
            {
                 //this will fired up when you will reach end of list
                //load your more data here
            }