如何通过物理滚动滚动到列表框中的下一个逻辑页面
我确实有一个列表框,它必须有 CanContentScroll==false 因为我需要能够平滑地滚动它。这使得物理滚动成为可能。
我还想按页滚动列表框,但如果我在列表框内部 ScrollViewer 上调用 PageDown 方法,第一行会被剪切,因为列表框高度不是行高的倍数。
我希望第一行始终完全可见,就像使用逻辑滚动时一样。
有人可以给我一个关于如何做到这一点的提示吗?
I do have a listbox which must have CanContentScroll==false because i need to be able to scroll it smoothly. This enables physical scrolling.
I also want to scroll the listbox by page, but if i call the PageDown method on the listbox internal ScrollViewer the first row gets cutted because the listbox height is not a multiple of the row height.
I want the first row to be always completely visible, like when using logical scrolling.
Can someone give me a hint on how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果向下滚动,然后选择上方的可见项,您将获得与虚拟化控件相同的非虚拟化
ItemsControl
(ScrollViewer.CanContentScroll="False"
) 效果容器与鼠标。这也可以通过代码完成。当
CanContentScroll
设置为 false 时,虚拟化将关闭,因此所有容器都将始终生成。要获取顶部可见容器,我们可以从顶部迭代容器,直到到达ScrollViewer
的VerticalOffset
。获得它后,我们可以简单地对其调用BringIntoView
,它会在顶部很好地对齐,就像使用虚拟化时一样。示例
在事件处理程序中的顶部可见容器上调用
BringIntoView
仅当您想要调用
PageDown
时才能实现此效果>,例如,在按钮单击中,您可以为ListBox
创建一个名为LogicalPageDown
的扩展方法。ListBoxExtensions
我在您的问题中注意到您已经获得了
ScrollViewer
,但如果其他人遇到此问题,我将向GetVisualChild
添加一个实现You'll get the same effect for a non virtualizing
ItemsControl
(ScrollViewer.CanContentScroll="False"
) as for a virtualizing one if you scroll down and then select the upper visible container with the mouse. This can also be done in code.When
CanContentScroll
is set to false, virtualizing is turned off so all containers will be generated at all times. To get the top visible container we can iterate the containers from the top until we reach theVerticalOffset
of theScrollViewer
. Once we got it we can simply callBringIntoView
on it and it will align nicely at the top just like it would if virtualization was being used.Example
Call
BringIntoView
on the top visible container in the event handlerTo only achieve this effect when you want to call
PageDown
, in a Button click for example, you can create an extension method forListBox
calledLogicalPageDown
.ListBoxExtensions
I noticed in your question that you already got the
ScrollViewer
but I'm adding an implementation toGetVisualChild
if anyone else comes across this question如果您将“新页面”的顶部项目滚动到视图中,是否会实现您想要的效果?
请参阅 ScrollIntoView< /a>.
If you scroll the top item of the "new page" into view, would that achieve what you're looking for?
See ScrollIntoView.