I have a GridView with multiple columns. I would like to display a ContextMenu only when an item in a specific menu is right-clicked on. Here’s what I have so far:
<GridView>
<GridViewColumn>
<!-- Show context menu for this column -->
<GridViewColumn.CellTemplate>
<DataTemplate>
...
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn>
<!-- Do not show context menu for this column -->
<GridViewColumn.CellTemplate>
<DataTemplate>
...
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
I tried adding a GridViewColumn.ContextMenu between the <GridViewColumn></GridViewColumn> tags but that does not seem to exist. I also tried adding it inside the GridViewColumn.CellTemplate and DataTemplate without any luck.
Any suggestions on how I can have a ContextMenu for a specific column?c
You should add it inside the first child of
DataTemplate(ie, it needs to be the child of aFrameworkElement).