How to get a relative position from a MouseEventArgs
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) ?
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) ?
Last edited by nikobarli on 12 May 2017, 09:16, edited 1 time in total.
Re: How to get a relative position from a MouseEventArgs
The location is given in screen coordinates. You can use PointFromScreen in Visual.h to transform to local coordinates:
And yes, we should improve our MouseEventArgs to be fully WPF compliant.
Code: Select all
/// 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;
Re: How to get a relative position from a MouseEventArgs
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.
Who is online
Users browsing this forum: No registered users and 1 guest