How to add context menu to wpf datagrid?

StillWorking28269 picture StillWorking28269 · Jul 20, 2010 · Viewed 51.6k times · Source

How does one add a ContextMenu to a DataGrid? I want to be able to right click anywhere on the DataGrid.

Answer

StillWorking28269 picture StillWorking28269 · Jul 20, 2010
<DataGrid>
    <DataGrid.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Click Me" Click="MenuItem_Click" />
        </ContextMenu>
    </DataGrid.ContextMenu>
</DataGrid>