添加将替换 listView 中滚动的按钮

发布于 2024-10-04 08:36:07 字数 236 浏览 0 评论 0原文

我想编写一些包含 2 个按钮和 listView 的控件。 按按钮 1 将向上滚动列表视图。 按按钮 2 将向下滚动列表视图。

列表视图的直接滚动将不可用 - (将不可见?)。

  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 ? ).

  1. I don't find the listview method 'scroll-up' / 'scroll-down' that i could callon the button event.

  2. How can i make the listview scroll to be always visible ?

Someone can help me here ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-10-11 08:36:07

这里有两种选择,一种比另一种更容易。

第一个选项(更简单,但有点老套的方法):使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文