简体   繁体   English

延迟后检查WPF控件拖放上的鼠标位置

[英]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. 我正在尝试在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. 作为此过程的一部分,一旦触发DragOver事件,如果鼠标悬停在节点上方一定时间,则需要扩展当前悬停的节点。

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. 我已经能够在触发的节点上使用DelayedAction成功延迟扩展,但是一旦延迟动作触发,我就无法成功检查鼠标的当前位置。 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. 我需要能够在延迟之后检查鼠标的当前位置,并且仅在鼠标仍位于节点上方时才展开节点。

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? 我使用的线程在这里可用: 如何在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. 我使用Win32方法在延迟后获得正确的鼠标位置,并通过命中测试使用它来获取鼠标下的当前TreeViewItem。

If the current TreeViewItem is the same as the TreeViewItem that triggered the DragOver event then I expand the node, or else do nothing. 如果当前的TreeViewItem与触发DragOver事件的TreeViewItem相同,则我将展开节点,否则不执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM