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 in WPF controls by default? Is there a setting, a workaround, or something obvious that I'm missing?
相关问题
- VNC control for WPF application
- Use JS/jQuery to scroll a div's content that h
- WPF Binding from System.Windows.SystemParameters.P
- Jscrollpane - Fires a function when isAtBottom
- XAML: Applying styles to nested controls
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"
.I have found how to achieve this using 3 mouse events (
MouseDown
,MouseUp
,MouseMove
). Their handlers are attached to theScrollViewer
element in the xaml below:It would be better to write a behaviour instead of events in code-behind, but not everyone has the necessary library, and also I don't know how to connect it with the
Canvas
.The event handlers:
If to remove the method calls
AddScrollSign
andRemoveScrollSign
this example will work. But I have extended it with 2 methods which set scroll icon:Example of icons:
And one last remark: there are some problems with the way
Press -> Immediately Release -> Move
. It is supposed to cancel scrolling if a user clicks the mouse left button, or any key of keyboard, or the application looses focus. There are many events and I don't have time to handle them all.But standard way
Press -> Move -> Release
works without problems.