简体   繁体   English

WPF ListView 通过按钮单击滚动整个页面(查看项目)

[英]WPF ListView scroll whole page (seen items) by button click

I've created a listview in WPF.我在 WPF 中创建了一个列表视图。 The items in there are changing their backgroundcolor by clicking, in this case i deactivated the listview prop 'Focusable'.那里的项目通过单击更改它们的背景颜色,在这种情况下,我停用了 listview 道具“Focusable”。 For my usecase (on a touchscreen) i want to hide the scrollbar and just scroll by clicking an up/down button at the bottom.对于我的用例(在触摸屏上),我想隐藏滚动条,只需单击底部的向上/向下按钮即可滚动。 One click should scroll the whole page (UP/DOWN) and show the next (so far hided) items.单击应该滚动整个页面(向上/向下)并显示下一个(到目前为止隐藏的)项目。 I'm seraching for a flexible solution and don't want to calculate pixels or smth like that (also the items haven't a fixed height, also the window)我正在寻找一个灵活的解决方案,不想计算像素或那样的东西(项目也没有固定的高度,窗口也没有)

Thanks in advance提前致谢

First off, it might benefit you to take a look at How do I ask a good question?首先,看看我如何提出一个好问题可能会对您有所帮助? . . Specifically, in your case it would be easier to understand the sitution if you included some of your XAML.具体来说,在您的情况下,如果您包含一些 XAML,则会更容易理解这种情况。 However, I do think I have a solution for you.但是,我确实认为我有一个解决方案。

ItemsControl s like the ListView support "content scrolling", meaning the ability to scroll by content/items instead of by pixel.ListView一样的ItemsControl支持“内容滚动”,这意味着能够按内容/项目而不是按像素滚动。 This question gives a solution to finding which items are currently visible in the ListView by accessing the internal ScrollViewer . 这个问题提供了一个解决方案,通过访问内部ScrollViewer来查找ListView中当前可见的项目。 ScrollViewer.VerticalOffset will tell you the index first visible item and ScrollViewer.ViewportHeight will tell you how many items are visible. ScrollViewer.VerticalOffset将告诉您索引第一个可见项目,而ScrollViewer.ViewportHeight将告诉您有多少项目可见。 To scroll to the "next page", you should just need to:要滚动到“下一页”,您只需要:

ScrollViewer.VerticalOffset += ScrollViewer.ViewportHeight;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM