How to get the diagram position from a mouse click

3 posts, 0 answers
  1. Gary
    Gary avatar
    6 posts
    Member since:
    Feb 2013

    Posted 07 Oct 2013 Link to this post

    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. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 10 Oct 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Gary
    Gary avatar
    6 posts
    Member since:
    Feb 2013

    Posted 10 Oct 2013 Link to this post

    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.
Back to Top