ContextMenu Top Left Position

5 posts, 0 answers
  1. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 13 Apr 2012 Link to this post

    I'm using a RadContextMenu on a Canvas.  When I select an item from the menu, I need to know the point in the Canvas in which I was when I opened the menu for placement of another control.  How do I get the top left position of the context menu?

    Thanks for your help.
  2. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 13 Apr 2012 Link to this post

    I do have a solution but I'd prefer to not do this.  I track mouse movements on the canvas and store the point into a class variable.  I then use that point to capture the point in which I opened the context menu.  Fortunately, when I move up and down the context menu list, the mouse position doesn't update because the menu has the focus at that point.

    BTW:  This is al done with the ScrollViewer I have around my canvas, not the canvas itself.
    canvasScrollViewer.MouseMove += canvasScrollViewer_MouseMove;

    Point _canvasMousePosition;
     
    void canvasScrollViewer_MouseMove(object sender, MouseEventArgs e)
    {
        _canvasMousePosition = e.GetPosition(canvasScrollViewer);
        lblCoordinates.Content = String.Format("X:  {0};  Y:  {1}",
            _canvasMousePosition.X, _canvasMousePosition.Y);
    }

  3. UI for WPF is Visual Studio 2017 Ready
  4. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 18 Apr 2012 Link to this post

    Hello,

    You can use the MousePosition property and it will return the coordinates you clicked on. You can access them on Opened event of the RadContextMenu or some other event. This should work for your scenario.

    Kind regards,
    Boyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 31 Jul 2012 Link to this post

    What are the coordinates in context to?  I right-click on a canvas that is hosted inside a scroll viewer.  Currently, when I scroll down and click on the same x/y on the canvas I the mouse position Point changes.
  6. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 31 Jul 2012 Link to this post

    I believe I found the problem.  I set the context menu to the ScrollViewer instead of the Canvas.  By asking the right question... it got me thinking down the correct path.
Back to Top
UI for WPF is Visual Studio 2017 Ready