简体   繁体   English

即使在WPF中处于外部控制之下,也要触发MouseUp事件

[英]Fire the MouseUp event even when outside control in WPF

I want to be able in my WPF application to detect the MouseUp event from anywhere. 我希望能够在WPF应用程序中从任何位置检测MouseUp事件。 That is to say, if the user clicks in the control and holds his click, then releases it outside the Control, I want my MouseUp event to fire. 也就是说,如果用户单击控件并保持其单击,然后将其释放到控件外,则我希望触发MouseUp事件。

I have done the MouseDown event, it works, but the MouseUp event isn't fired if released outside the Window . 我已经完成了MouseDown事件,它可以工作,但是如果在Window外部释放MouseUp事件,则不会触发该事件。

Add the CaptureMouse method in your MouseButtonDown handler 在您的MouseButtonDown处理程序中添加CaptureMouse方法

You can look up here on what it actually does. 您可以在这里查看其实际功能。

Another way is using the windows API's for mouse_event described here: Simulating Mouse Clicks 另一种方法是将Windows API用于mouse_event,如下所述: 模拟鼠标点击

I would use the CaptureMouse listed above first but if that doesn't work for you this one should. 我将首先使用上面列出的CaptureMouse,但是如果那对您不起作用,则应该使用它。

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

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