【问题标题】:Adding a 'Load More' button below ItemsControl in windows phone 8.1 Silverlight application在 windows phone 8.1 Silverlight 应用程序中的 ItemsControl 下方添加“加载更多”按钮
【发布时间】:2014-07-23 22:01:06
【问题描述】:

我正在实现一个 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

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

解决了问题,但是ItemsControl的性能很差。您有更好的想法或建议吗?

谢谢 维诺特·塞尔瓦拉杰

【问题讨论】:

    标签: silverlight windows-phone-8.1 itemscontrol


    【解决方案1】:

    我至少花了 2 个小时来弄清楚为什么虚拟化在这种情况下会丢失,但我设法解决这个问题的唯一方法是坚持使用您首先提供的 ControlTemplate ->

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

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

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

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多