一种获取“按钮按下事件”的方法对于 WPF ScrollViewer 控件
我的自定义控件使用 ScrollViewer,我想确定用户何时按下水平滚动增量按钮,而控件已经滚动到水平最大值。
查看器包含一个画布,其想法是,如果用户尝试使用按钮滚动超过其范围,画布将扩展。
ScrollViewer
似乎没有任何与按钮具体相关的事件,并且 ScrollChanged
本身没有用,因为当栏处于其范围时它不会触发。
.Net Reflector 并没有产生太多的用途。我能得到的最接近的是为 mouseLeftButtonDown 添加一个事件处理程序,我可以看到查看器状态,但不知道如何确定鼠标事件是否源自按钮。
任何人都可以想出一种方法来做到这一点吗?
My custom control uses a ScrollViewer
and I want to determine when the user presses the horizontal scroll increment button while the control is already scrolled to the horizontal max.
The viewer contains a canvas and the idea is the canvas will extend if the user tries to scroll past its extent with the buttons.
ScrollViewer
doesn't appear to have any events which relate to the buttons specifically and ScrollChanged
is no use on its own since it doesn't trigger when the bar is at its extent.
.Net Reflector hasn't yielded much of use. The closest I can get is adding an event handler for mouseLeftButtonDown, I can see the viewers state but not how to determine whether the mouse event originated from the button.
Can anyone think of a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试通过 VisualTree 获取控件的按钮,并将处理程序附加到它们的单击事件。
编辑:我编写了一个扩展方法,用于通过路径获取可视化树的项目:
如果您的 ScrollViewer 被称为 sv 您应该能够获得如下按钮:
注意:按钮仅在相应的滚动条时存在已启用。通过使用其他数据类型,扩展方法可能会提高性能。
You could try to get the buttons of the control via the
VisualTree
and attach a handler to their click events.Edit: I wrote an extension method for getting items of visual tree via a path:
If your
ScrollViewer
is called sv you should be able to get the buttons like this:Note: Buttons only exist if the respective scollbar is enabled. The extension method could probably improved in terms of performance by using other datatypes.