How can I make WPF ScrollViewer middle-click-scroll?

后端 未结 2 1562
心在旅途
心在旅途 2021-02-19 19:22

Clicking the middle mouse button (aka: mouse wheel) and then moving the mouse down slightly lets users scroll in IE, and most Windows apps. This behavior appears to be missing

2条回答
  •  梦谈多话
    2021-02-19 19:30

    vorrtex posted a nice solution, please upvote him!

    I do have some suggestions for his solution though, that are too lengthy to fit them all in comments, that's why I post a separate answer and direct it to him!

    You mention problems with Press->Release->Move. You should use MouseCapturing to get the MouseEvents even when the Mouse is not over the ScrollViewer anymore. I have not tested it, but I guess your solution also fails in Press->Move->Move outside of ScrollViewer->Release, Mousecapturing will take care of that too.

    Also you mention using a Behavior. I'd rather suggest an attached behavior that doesn't need extra dependencies.

    You should definately not use an extra Canvas but do this in an Adorner.

    The ScrollViewer itsself hosts a ScrollContentPresenter that defines an AdornerLayer. You should insert the Adorner there. This removes the need for any further dependency and also keeps the attached behavior as simple as IsMiddleScrollable="true".

提交回复
热议问题