getting hold of ContextMenu parent

hi,

i am using context menu like this for my canvas object. the problem is i have more than one canvas i need to catch hold of were did the request originate from (who the sender is). the context menu is giving parent as system.windows.controls.primitives.popup as the parent of contextmenu, but i need to catch hold of the canvas from that event.

can somebody help me here please.

System.Windows.Controls.ContextMenu c = new ContextMenu();

MenuItem mn = new MenuItem();

mn.Header = " new";

canvas1.ContextMenu = c;

canvas1.ContextMenu.Items.Add(mn);

mn.PreviewMouseLeftButtonDown+=new System.Windows.Input.MouseButtonEventHandler(mn_PreviewMouseLeftButtonDown);

thanks prasanth.



Answer this question

getting hold of ContextMenu parent

  • Cesar Ronchese

    try this

    Canvas c = ((sender as FrameworkElement).Parent as ContextMenu).PlacementTarget as Canvas;



  • getting hold of ContextMenu parent