添加一个';加载更多';windows phone 8.1 Silverlight应用程序中Items控件下方的按钮

添加一个';加载更多';windows phone 8.1 Silverlight应用程序中Items控件下方的按钮,silverlight,windows-phone-8.1,itemscontrol,Silverlight,Windows Phone 8.1,Itemscontrol,我正在实现一个RSS阅读器应用程序,并使用ItemsControl显示新闻项目。我尝试在ItemsControl下面添加一个“加载更多”按钮,如下所示 <Grid x:Name="LayoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="auto" /> </Grid.RowDefinitions>

我正在实现一个RSS阅读器应用程序,并使用ItemsControl显示新闻项目。我尝试在ItemsControl下面添加一个“加载更多”按钮,如下所示

<Grid x:Name="LayoutRoot">
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="auto" />
   </Grid.RowDefinitions>       

   <ItemsControl x:Name="itemsControl"  Margin="10,10,10,0" Grid.Row="0">
     <ItemsControl.ItemsPanel>
       <ItemsPanelTemplate>
         <VirtualizingStackPanel>                       
       </VirtualizingStackPanel>
     </ItemsPanelTemplate>

    </ItemsControl.ItemsPanel>
      <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
          <ScrollViewer>
            <ItemsPresenter />
          </ScrollViewer>
         </ControlTemplate>
       </ItemsControl.Template>
     </ItemsControl>

    <TextBlock x:Name="loadMoreTextBlock" Grid.Row="1" Text="Load more"/>
</Grid> 
  <ItemsControl.Template>
    <ControlTemplate TargetType="ItemsControl">
      <ScrollViewer>
        <StackPanel>
          <ItemsPresenter />
          <TextBlock x:Name="loadMoreTextBlock" Text="Load more"/> 
         </StackPanel>               
      </ScrollViewer>
     </ControlTemplate>
   </ItemsControl.Template>

但是文本块不会显示在滚动的最后,并且在根网格中始终可见。我想在用户向下滚动到底部时,仅在itemscontrol的末尾显示“加载更多”文本

像这样更改ItemsControl.Template

<Grid x:Name="LayoutRoot">
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="auto" />
   </Grid.RowDefinitions>       

   <ItemsControl x:Name="itemsControl"  Margin="10,10,10,0" Grid.Row="0">
     <ItemsControl.ItemsPanel>
       <ItemsPanelTemplate>
         <VirtualizingStackPanel>                       
       </VirtualizingStackPanel>
     </ItemsPanelTemplate>

    </ItemsControl.ItemsPanel>
      <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
          <ScrollViewer>
            <ItemsPresenter />
          </ScrollViewer>
         </ControlTemplate>
       </ItemsControl.Template>
     </ItemsControl>

    <TextBlock x:Name="loadMoreTextBlock" Grid.Row="1" Text="Load more"/>
</Grid> 
  <ItemsControl.Template>
    <ControlTemplate TargetType="ItemsControl">
      <ScrollViewer>
        <StackPanel>
          <ItemsPresenter />
          <TextBlock x:Name="loadMoreTextBlock" Text="Load more"/> 
         </StackPanel>               
      </ScrollViewer>
     </ControlTemplate>
   </ItemsControl.Template>

解决了该问题,但ItemsControl的性能较差。你有什么更好的想法或建议吗

谢谢
Vinoth Selvaraj

我已经花了至少两个小时来弄清楚为什么虚拟化在这个场景中会丢失,但我设法解决这个问题的唯一方法是坚持您首先提供的控制模板->

<ControlTemplate TargetType="ItemsControl">
    <ScrollViewer>
        <ItemsPresenter />
    </ScrollViewer>
</ControlTemplate>

并确保将“加载更多”项放入绑定ItemsSource的viewmodel集合中。在这种情况下,您可能需要对列表的最后一个成员应用不同的ItemTemplate,这可以通过自定义DataTemplateSelector实现。 但是,当单击“加载更多”时,您必须再次将此特殊列表项重新定位到列表的末尾

总的来说,我建议你提出第二种方法,即把更多的负载放在列表下面,或者考虑改变整个概念并使用某种分页机制,而你只能看到列表中的前几百个条目,并按下一些按钮显示前/下百个。