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
110
Hide Context Menu Items
posted

Hi! I'm trying to hide a context menu item when I click on a cell that has a certain header value. I'm able to get the header value by using the XamContextMenu's Opening event, but when I try to access either the context menu itself or the menu item, they are both null. I've tried accessing them in the Opened event, and I even tried a timer to wait until the menu was already open, but they _always_ come back as null.

Here's the XAML I have:

<ig:ContextMenuService.Manager>
 <ig:ContextMenuManager x:Name="MyManager">
 <ig:ContextMenuManager.ContextMenu>
 <ig:XamContextMenu Name="rightClickMenu" Opening="xamContextMenuOpening">
 <ig:XamMenuItem Header="Add Row"  x:Name="AddRow" Click="addRowClick" />
                <ig:XamMenuItem Header="Insert Row"  x:Name="InsertRow" Click="insertRowClick" />
                <ig:XamMenuItem Header="Delete Row" x:Name="DeleteRow" Click="deleteRowClick" />
                <ig:XamMenuItem Header="Flip as Header Row" x:Name="SetHeaderRow" Click="setHeaderRowClick" />
                <ig:XamMenuItem Header="Copy Down Value" x:Name="CopyDownValue" Click="copyValueDownClick"/>
                <ig:XamMenuSeparator />
            ig:XamContextMenu>         ig:ContextMenuManager.ContextMenu>     ig:ContextMenuManager> ig:ContextMenuService.Manager>

If i try to access 'rightClickMenu' or 'CopyDownValue' from the code, they come back as null no matter what, even if the menu is open. How would I go about hiding a menu item through the code if I can't access the control?

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Eric,

    I believe that the reason you will not be able to access the XamContextMenu or the items inside of it directly may be due to the fact that the context menu is a Popup at its root, and as such, is likely in a different visual tree than the one you are trying to access it from.

    In order to access the XamContextMenu instead, I would recommend that you cast the sender of the Opening or Opened event to the XamContextMenu that you are trying to access and navigate through the Items collection of that menu. Doing this should allow you to access the XamMenuItems that you have placed in this collection and show or hide them based on the PlacementTarget or the PlacementTargetResolved of the XamContextMenu. These "placement" properties should allow you to determine where the XamContextMenu is placed, which you can use to determine which menu items should be hidden.

    I have attached a sample project to demonstrate the above. I hope this helps.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XamContextMenuItemVisibilityCase.zip
Children
No Data