This is a migrated thread and some comments may be shown as answers.

How to get the diagram position from a mouse click

2 Answers 337 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 07 Oct 2013, 03:35 PM
Hi,

We display a context menu when the user right clicks a location within the RadDiagram.  How would we get the position in the diagram where the user clicked?  
This doesn't appear to be as simple as getting the MousePosition of the menu (or combining it with PointFromScreen) as we need to take account of Pan / Zoom / Scrolling.

2 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 10 Oct 2013, 12:47 PM
Hi Gary,

In order to calculate the exact position of the mouse you can take into account the current position of the Viewport of the RadDiagram control. This position shows how much and in which direction you have panned. You can calculate this position by getting the Viewport.Top and Viewport.Left properties.

Furthermore, when you have that position, you need to sum the Left property and the X property of your click position (also the Top and the Y) to open the ContextMenu inside the current viewport.

I hope this information is helpful.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Gary
Top achievements
Rank 1
answered on 10 Oct 2013, 12:53 PM
Hi Pavel,

We have solved this by calling GetTransformedPoint:

var menu = (RadContextMenu) sender;
           menu.Items.Clear();
           var transformedPoint = AssociatedObject.GetTransformedPoint(menu.MousePosition);

This appears to be doing exactly as we require.

Gary.
Tags
Diagram
Asked by
Gary
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Gary
Top achievements
Rank 1
Share this question
or