CodeMouse92 CodeMouse92 - 1 year ago 87 Question

Get Mouse Position on Canvas (But NOT on window)?

I have a project in WPF 4 and 2010.

I have a canvas inside a window. The window is full screen, but the canvas is set to a solid 640x480 in the center of the window. I need to get the mouse position inside of the canvas, but NOT inside of the window. How do I do this?

Answer Source

Doesn't this work?

Point p = Mouse.GetPosition(canvas);

The position of the mouse pointer is calculated relative to the specified element with the upper-left corner of element being the point of origin,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download