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.
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.