我知道通过编辑 ListBox
像这样的默认样式,我可以有一个 Button
在 ListBox
的最后.
<ScrollViewer x:Name="ScrollViewer" ...>
<StackPanel>
<ItemsPresenter />
<Button />
</StackPanel>
</ScrollViewer>
但是,这样做会破坏
ListBox
的虚拟化和渲染时间变得非常长。我能想到的只有
View 模型,并有一个
Visibility
名为 的虚拟对象中的属性ButtonGridVisibility 并将其设置为 Visibility.Visible
. ListBox
的 ItemTemplate
,有两个Grids
.一台显示器正常的项目布局,另一个显示加载更多
Button
.然后切换他们的
Visibility
基于 ButtonGridVisibility 属性(property)。 这可能有效,但我只是想知道是否有更简单/更好的方法?
最佳答案
我知道这是一篇旧帖子,但以防万一有人偶然发现:
有一个 LongListSelector 控件 available out of the box in WP8或作为 Windows Phone Toolkit 的一部分对于 WP7,它非常巧妙地支持这种情况。如果要在最后一项之后(或第一项之前)添加特定内容,只需设置控件的 ListFooter 或 ListHeader 即可。您可以将任何内容放入其中,此内容将与其余项目一起滚动。
所以对于 WP7,这看起来像这样:
<toolkit:LongListSelector ItemsSource="{Binding Items}">
<toolkit:LongListSelector.ListFooter>
<Grid>
<Button />
</Grid>
</toolkit:LongListSelector.ListFooter>
</toolkit:LongListSelector>
哪里
toolkit
是 xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
关于silverlight - 在列表框的末尾添加加载更多按钮而不会丢失虚拟化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8489508/