在ListBox的末尾添加“加载更多"按钮而不丢失虚拟化功能? [英] Add a Load More Button at the end of ListBox without losing Virtualization?

查看:52
本文介绍了在ListBox的末尾添加“加载更多"按钮而不丢失虚拟化功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道通过这样编辑ListBox的默认样式,我可以在ListBox的末尾有一个Button.

I know by editing the ListBox's default style like this, I can have a Button at the very end of the ListBox.

<ScrollViewer x:Name="ScrollViewer" ...> 
    <StackPanel>
        <ItemsPresenter />
        <Button />
    </StackPanel>
</ScrollViewer> 

但是,这样做会破坏ListBox的虚拟化,渲染时间会非常长.

However, doing this will break the ListBox's Virtualization and the rendering time becomes really long.

我唯一能想到的是

  1. 创建一个虚拟项目并将其添加到我的项目集合的末尾 视图模型,并在名为 ButtonGridVisibility 的虚拟对象中具有Visibility属性,并将其设置为Visibility.Visible.
  2. 在我的ListBoxItemTemplate中,有两个Grids.一台显示器 正常的项目布局,另一个则显示加载更多 Button. 然后根据 ButtonGridVisibility 属性切换其Visibility.
  1. Create a dummy item and add it to the end of my item collection in the viewmodel, and have a Visibility property in the dummy object called ButtonGridVisibility and set it to Visibility.Visible.
  2. In my ListBox's ItemTemplate, have two Grids. One displays the normal item layout, the other displays the Load More Button. Then toggle their Visibility based on ButtonGridVisibility property.

这可能有效,但我只是想知道是否有任何更简便/更好的方法?

This might work but I just wonder if there is any easier/better way?

推荐答案

我知道这是一篇过时的文章,但万一有人偶然发现:

I know this is an old post but in case some people stumble upon this:

有一个LongListSelector控件 Windows Phone Toolkit的一部分获得. a>对于WP7而言,它很好地支持了这种情况.如果要在最后一项之后(或在第一项之前)添加特定内容,只需设置控件的ListFooter或ListHeader.您可以将任何内容放入其中,该内容以及其余项目将相应地滚动.

There is a LongListSelector control available out of the box in WP8 or as part of the Windows Phone Toolkit for WP7 which supports this scenario quite neatly. If you want to add specific content after the last item (or before the first item), you can simply set the ListFooter or ListHeader of the control. You can put any content inside and this content will be scrolled accordingly, together with the rest of the items.

因此对于WP7,它看起来像这样:

So for WP7 this would look like this:

<toolkit:LongListSelector ItemsSource="{Binding Items}">
    <toolkit:LongListSelector.ListFooter>
        <Grid>
            <Button />
        </Grid>
    </toolkit:LongListSelector.ListFooter>
</toolkit:LongListSelector>

其中toolkitxmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

这篇关于在ListBox的末尾添加“加载更多"按钮而不丢失虚拟化功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆