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
565
My ContextMenu won't display at all
posted

This one is driving me up the wall.  I want to see my right-click ContextMenu show up.

I don't care what the target is or if it's on a row or header or whatnot; I just want to see *something* when I right click anywhere on the grid.  Right now, nothing happens at all when I right-click.

This is my snippet:

<my:XamDataGridTheme="Aero" Grid.Row="1" Name="_grdPositions" UpdateMode="OnRecordChange">
<my:XamDataGrid.Resources>
        <ContextMenu x:Key="contextMenu" IsEnabled="True" AllowDrop="True">
                <ContextMenu.Items>
                        <MenuItem Header="uno">foo</MenuItem>
                        <MenuItem Header="dos">bar</MenuItem>
                </ContextMenu.Items>
        </ContextMenu>
</my:XamDataGrid.Resources>

Am I missing something here?  Is there some right-click handler that I need to initialize?  I'm really stumped; this seems like a really simple thing to do, but it's just not happening.

Thanks.

  • 69686
    Suggested Answer
    posted

    Hello,

    From what I can see, you have defined the ContextMenu as a resource inside the XamDataGrid's resources but never applied it. You have set the x:key and therefore you can use the ContextMenu as StaticResource and set the ContextMenu of the XamDataGrid to that StaticResource. Another way to go is directly set this at the Context Menu property, like so:

    <igDP:XamDataGrid.ContextMenu>

                    <ContextMenu IsEnabled="True" AllowDrop="True">

                        <ContextMenu.Items>

                            <MenuItem Header="uno">foo</MenuItem>

                            <MenuItem Header="dos">bar</MenuItem>

                        </ContextMenu.Items>

                    </ContextMenu>

                </igDP:XamDataGrid.ContextMenu>

    You can find some more advanced ways to show a context menu according to which element you have selected here in this blog post.

    Hope this helps.