nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

How to get a relative position from a MouseEventArgs

12 May 2017, 07:47

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) ?
Last edited by nikobarli on 12 May 2017, 09:16, edited 1 time in total.
 
User avatar
jsantos
Site Admin
Posts: 2906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to get a relative position from a MouseEventArgs

12 May 2017, 07:55

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.
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: How to get a relative position from a MouseEventArgs

12 May 2017, 09:27

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