ListView - 当我滚动时滚动条高度不断变化
我有一个使用 ListViewItems 显式填充(无绑定)的 ListView。 大多数项目需要可见,其他项目应保持折叠状态。所有物品的高度相同。
问题是,如果我有 100 个项目,前 60 个项目可见,而底部 40 个项目处于折叠状态,那么滚动条的高度就会变成基于所有 100 个项目都处于可见状态的假设,并且滚动条的高度变得小于应该是的。但是当我向下滚动到 60 时,它意识到其余 40 项处于折叠状态,因此增加了滚动条的高度以使其适合列表视图中的 60 项。
我最初认为这可能是因为虚拟化。但我没有将任何数据绑定到列表视图。我还尝试将需要处于折叠状态的项目的高度设置为 0,但这没有给我想要的结果。
我需要的是,如果有 60 个可见项目和 40 个折叠项目,则滚动条的高度应仅基于列表视图中的 60 个项目,并且应保持不变。 有可能实现吗?
I have a ListView which is explicitly populated (no binding) with ListViewItems.
Most of the items need to Visible and others should remain collapsed. All the items are of the same height.
The problem is if I have 100 items and first 60 are visible and the bottom 40 are in collapsed state, the scroll bar's height become something based on the assumption that all the 100 items are in visible state and the scroll bar's height becomes less than what it should be. But when I scroll down to 60, it realizes that the rest 40 are in collapsed state and therefore increases the scroll bar's height to make it appropriate for 60 items in the list view.
I initially thought it may be because of virtualization. But I dod not have any binding of data to the list view. I also tried to set the height of the items to 0 that need to be in collapsed state which did not give me the desired result.
What I need is, if there are 60 items visible and 40 collapsed then the scroll bar's height should be based on only 60 items in the list view and should remain constant.
Is it possible to achieve?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了完全相同的问题,答案可以在这里找到: 当内容高度可变时,列表框滚动条滑块会改变大小
很快,在 ListBox 上添加
ScrollViewer.CanContentScroll="False"
,滚动条将具有恒定的高度,无论在折叠项目的数量。顺便说一句,我知道这个问题已经有近两年的历史了,但我想把它留作将来参考。
I had exactly the same problem, and the answer can be found here: Listbox scrollbar thumb changes size when content is variable height
Shortly, add
ScrollViewer.CanContentScroll="False"
on the ListBox and the scrollbar will have constant height regardless on the number of collapsed items.By the way, I am aware that the question is almost 2 years old, however I'd like to leave it for future reference.
我不确定是什么让您决定这不是虚拟化,因为它必须是虚拟化。尝试关闭虚拟化:
I'm not sure what made you decide it wasn't virtualization, as that is what it must be. Try turning off virtualization: