c# - How do I convert ContextMenuEventArgs cursor location to window coordinates -
i'm trying display context menu user clicks mouse in wpf application. i've handled opencontextmenu event , handler has pair of doubles, e.cursorleft , e.cursortop coordinates of mouse click relative control clicked (in case datagridcell). if display context menu using coordinates appears relative application window offset cursor amounts.
how can convert datagridcell-relative cursor coordinates window coordinate space?
you can use uielement.translatepoint(point, visual) method convert coordinates 1 control's coordinate space another. following code should want (not tested!):
point target = mydatagridcell.translatepoint(new point(e.cursorleft, e.cursortop), application.current.mainwindow); however, if want display context menu, assign frameworkelement.contextmenu property control should show context menu. way, position positioned @ mouse cursor automatically. if have more complicated scenario, might still use method above.
Comments
Post a Comment