tags:

views:

318

answers:

1

How can you convert the System.Windows.Point that is returned by MouseDevice.GetPosition(null), which is relative to a WPF window into screen coordinates.

There's this hack (How to get control location in screen coordinate system) but it's almost over two years old and will only work under certain constraints. As that article describes this is not trivial to get right so I'd like to rely on a WPF method if possible.

I'm using .NET Framework 4.0 so I am not worried about backward compatibility with earlier .NET framework versions.

+2  A: 

You need this:

http://msdn.microsoft.com/en-us/library/system.windows.media.visual.pointtoscreen.aspx

If you call it on a control and pass it (0, 0), it gives you the top-left corner of the control in screen coordinates.

Or you can pass it (ActualWidth, ActualHeight) and you'll get the bottom-right corner.

Daniel Earwicker
So obvious I missed it! :-)
Jeff Stong