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
65
XamDataGrid ContextMenu
posted

I have a simple ContextMenu with Copy/Paste menu items in it.  While this works fine, I need to add it to many many grids so I need a way to reuse the code in multiple locations.  Any ideas?

Thisis  what I currently have.

 

<igDP:XamDataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="Copy"/>
                    <MenuItem Command="Paste"/>                    

                </ContextMenu>
</igDP:XamDataGrid.ContextMenu>
Thanks,
  • 2677
    posted

    Hello Shabel,

    You can easily make the Context menu a global resource.  Inside of you App.xaml file, fine the Resources section and place the context menu there and give it a Key.

    <Application.Resources>
        <ContextMenu x:Key="GridContextMenu">
            <MenuItem Header="Copy"/>
            <MenuItem Header="Paste"/>
        </ContextMenu>
    </Application.Resources>

    Then, just set the grids ContextMenu to this resource.

    <igDP:XamDataGrid ContextMenu="{StaticResource GridContextMenu}"

    Now you can use this context menu on any grid inside of the application.  Hope this helps.