Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
485
What object is the context menu attached to?
posted

I am creating a right click menu using XamContextMenu that I am attaching to XamMenuItems in a XamMenu. The menu displays and the click even fires. But, how can I determine what object the context menu is attached to? 

I need to get a reference to the object which was right-clicked on to bring up the context menu. 

thanks,

BOb

 

Parents
  • 5595
    Verified Answer
    posted

    Hi,

    You can hook up to the XamContextMenu's Opening / Opened event and from the event handler obtain a reference to the XamMenuItem that was clicked by calling the GetClickedElement() off the event arguments object, here is a sample code:

    <ig:ContextMenuService.Manager>
                    <ig:ContextMenuManager OpenMode="RightClick">
                        <ig:ContextMenuManager.ContextMenu>
                            <ig:XamContextMenu x:Name="mnuContext" Opening="mnuContext_Opening">
                                <ig:XamMenuItem x:Name="mnuName" Header="Some Header"/>
                            </ig:XamContextMenu>
                        </ig:ContextMenuManager.ContextMenu>
                    </ig:ContextMenuManager>
                </ig:ContextMenuService.Manager>

     
            private void mnuContext_Opening(object sender, OpeningEventArgs e)
            {
                var item = e.GetClickedElements<XamMenuItem>().SingleOrDefault();
                    // do something with the item
            }

    HTH,

Reply Children
No Data