Page 1 of 1

How to get a relative position from a MouseEventArgs

Posted: 12 May 2017, 07:47
by nikobarli
MouseEventArgs has a member 'position' which seems containing the mouse location relative to the root XAML element.
The question is, how can I convert it to a location relative to the element I choose (similar to WPF MouseEventArgs. GetPosition(IInputElement relativeTo) API) ?

Re: How to get a relative position from a MouseEventArgs

Posted: 12 May 2017, 07:55
by jsantos
The location is given in screen coordinates. You can use PointFromScreen in Visual.h to transform to local coordinates:
/// Converts a Point in screen coordinates into a Point that represents the current coordinate
/// system of the Visual
Drawing::Point PointFromScreen(const Drawing::Point& point) const;

/// Converts a Point that represents the current coordinate system of the Visual into a Point
/// in screen coordinates
Drawing::Point PointToScreen(const Drawing::Point& point) const;
And yes, we should improve our MouseEventArgs to be fully WPF compliant.

Re: How to get a relative position from a MouseEventArgs

Posted: 12 May 2017, 09:27
by nikobarli
Thanks it works. So the "screen" coordinate is the coordinate system related to the Xaml root element. So I just need to call child->PointFromScreen(args.position) to get the position relative to the child element.