Search code examples
wpfvb.netcanvasmousemouse-position

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


I have a project in WPF 4 and vb.net 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?


Solution

  • 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,