WPF: How do I allow scrolling with the mouse wheel in a ListView while dragging ListView items?
Asked Answered
B

1

10

I have implemented drag and drop in a ListView in my WPF application. Items can be dragged and dropped inside the ListView, and also into a TreeView that is beside the ListView.

Currently, I have it set up so that when you drag to the bottom of the ListView, it automatically scrolls down the list.

What I'd like to know is if there's any way to be able to scroll through the ListView with the mouse wheel while I'm dragging its items? It seems like the mouse wheel events aren't being fired while I'm dragging.

Beacon answered 29/5, 2009 at 15:5 Comment(7)
You want to use the mouse wheel and the left mouse button at the same time? Geez, I'm not nearly that coordinated.Edan
Just wondering: Who would ever use that? Enough people have problems with drag and drop already, scrolling simultaneously doesn't sound much easier to perform.Fennel
I would use it, and apparently we absolutely need it to happen. What type of drag-and-drop problems are you talking about?Beacon
The mouse wheel events are being fired. They are just being intercepted and marked as handled long before your handler gets a chance at them. Unfortunately I don't think there exists a PreviewScroll event.Yun
To start, I recommend using Spy++ to watch mouse events flowing through the WMQ when you are attempting to perform this action. Confirm scrolling generates messages while a drag is in progress. Seeing the messages will better prepare you for handling them using interop.Tenuous
This question stackoverflow.com/questions/4820095 says that you'll most likely need to resort to some very ugly and complex hacks to do that. Although, there may be people out there who are aware of the more elegant solution. I would use this also. In fact I do use dragging and scrolling when arranging tiles on a Win 8.1 Start screen as well as moving items in my Wasteland 2 inventory.Raker
Usually in any application you scroll by moving the entry while dragging at the border of the list. e.g. Scroll down, when the item is at the very bottom of the list. I think this is what most users are used to.Seismograph
P
0
  1. create (and start) mouse hook helper before DragDrop.DoDragDrop(...)
  2. analyze mouse wheel (+ check if mouse over control)
  3. stop (dispose) mouse hook helper after DoDragDrop() operation

Note: always stop mouse hook helper, because it can freeze application when it dispose on Window close (I see it on XP).

here you can find one MouseHook, adopt it (I found bug:)) or something like it.

Poling answered 13/9, 2015 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.