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?
You could try to get the buttons of the control via the
VisualTreeand attach a handler to their click events.Edit: I wrote an extension method for getting items of visual tree via a path:
If your
ScrollVieweris 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.