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

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

问题描述

我知道通过像这样编辑 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.一台显示器正常的项目布局,另一个显示Load More 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 控件 在 WP8 中开箱即用 或作为 Windows Phone 工具包的一部分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"

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

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