WPF主窗口外不会触发鼠标移动 [英] Mouse Move not trigger outside WPF Main Window

查看:78
本文介绍了WPF主窗口外不会触发鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得鼠标相对于屏幕坐标的位置.我正在使用以下代码来做到这一点.

I want to get mouse position relative to screen coordinates. I am using the following code to do that.

window.PointToScreen(Mouse.GetPosition(window));

它正在按预期方式工作.但是我的MouseMove事件没有在MainWindow外部触发.也就是说,如果我将鼠标移到桌面上并恢复了窗口,就可以了.

It is working as expected. But my MouseMove event not firing outside the MainWindow. That is if I move my mouse over desktop with my window restored.

任何想法都值得赞赏.

推荐答案

使用CaptureMouse()方法.

Use the CaptureMouse() method.

对于上面的示例,您可以添加:

For your example above, you could add:

window.CaptureMouse();

在MouseDown事件处理程序内部的代码后面.

in your code-behind inside the MouseDown event handler.

然后您需要致电:

window.ReleaseMouseCapture();

位于MouseUp事件处理程序内部代码的后面.

in your code-behind inside the MouseUp event handler.

这篇关于WPF主窗口外不会触发鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆