Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse Move not trigger outside WPF Main Window

Tags:

wpf

capture

mouse

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

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

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.

Any ideas appreciated.

like image 837
WPF Lover Avatar asked Feb 02 '23 05:02

WPF Lover


1 Answers

Use the CaptureMouse() method.

For your example above, you could add:

window.CaptureMouse();

in your code-behind inside the MouseDown event handler.

You then need to call:

window.ReleaseMouseCapture();

in your code-behind inside the MouseUp event handler.

like image 80
Curtis Avatar answered Feb 06 '23 11:02

Curtis