coffeecoder
coffeecoder

Reputation: 735

Check mouse position on WPF Control Drag and Drop after a delay

I am trying to implement drag and drop behaviour within a WPF Treeview. As part of this I need to expand the currently hovered over node if the mouse has been over the node for a set period of time once the DragOver event has been triggered.

I have been able to successful delay the expansion using a DelayedAction on the node that triggered, but I have been unable to successful check the current position of the mouse once the delayed action has triggered. Currently, even if the mouse has moved off the node and the click released, after the delay, the node will still expand.

I need to be able to check the current position of the mouse after the delay, and only expand the node if the mouse is still over the node.

Upvotes: 0

Views: 1230

Answers (1)

coffeecoder
coffeecoder

Reputation: 735

I was able to solve this with an answer from a different question here. The thread I used is available here: How do I get the current mouse screen coordinates in WPF?

I used the Win32 approach to get the correct mouse position after the delay and use this to get the current TreeViewItem under the mouse by using a hit test.

If the current TreeViewItem is the same as the TreeViewItem that triggered the DragOver event then I expand the node, or else do nothing.

Upvotes: 1

Related Questions