添加将替换 listView 中滚动的按钮
我想编写一些包含 2 个按钮和 listView 的控件。 按按钮 1 将向上滚动列表视图。 按按钮 2 将向下滚动列表视图。
列表视图的直接滚动将不可用 - (将不可见?)。
我没有找到可以调用按钮事件的列表视图方法“向上滚动”/“向下滚动”。
如何使列表视图滚动始终可见?
有人可以在这里帮助我吗?
谢谢。
i want to write some control that will contain 2 button and listView.
Pressing button 1 will scroll the listview up.
Pressing button 2 will scroll the listview down.
The direct scroll of the listview will be unavailable - ( will be invisible ? ).
I don't find the listview method 'scroll-up' / 'scroll-down' that i could callon the button event.
How can i make the listview scroll to be always visible ?
Someone can help me here ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有两种选择,一种比另一种更容易。
第一个选项(更简单,但有点老套的方法):使用 VisualTreeHelper,获取对 ListView 的 ControlTemplate 中的 ScrollViewer 的引用。然后,您可以使用 LineUp 和 LineDown 方法上下滚动内容,并使用静态 SetVerticalScrollBarVisibility 方法隐藏滚动条。我个人不会使用这种方法,因为我不喜欢依赖可以更改的可视化树。
第二个选项(有点难,但如果你知道怎么做的话也不算太糟糕):为 ListView 编写一个新的控制模板(可能需要更改 ScrollViewer + ScrollBar 的模板),添加两个调用 ScrollBar.LineUpCommand 的按钮和ScrollBar.LineDownCommand。如果您想这样做,我建议您获取 ShowMeTheTemplate 的副本,然后您只需复制并粘贴原始文件并进行修改即可。
希望这有助于为您指明正确的方向。
You have two options here, one is easier than the other.
First option (the easier, but slightly hacky way): Using the VisualTreeHelper, get a reference to the ScrollViewer in the ListView's ControlTemplate. Then you can use the LineUp and LineDown methods to scroll the content up and down and the static SetVerticalScrollBarVisibility method to hide the scrollbar. I personally wouldn't use this approach because I don't like relying on the Visual Tree which can change.
Second option (a bit harder, but not too bad if you know how): Write a new Control Template for the ListView (might need to alter the templates for it's ScrollViewer + ScrollBar), adding in two buttons that call the ScrollBar.LineUpCommand and ScrollBar.LineDownCommand. If you want to do this, I'd suggest getting a copy of ShowMeTheTemplate, then you can just copy and paste the original(s) and modify.
Hope this helps point you in the right direction.