Datagrid: ContextMenu for Column and Row Headers

Oct 31, 2008 at 10:43 AM

is there a way to get context menus specifically on the column and row headers?

<datagrid.ContextMenu>  puts it everywhere on the datagrid, but I woul like to have different menues for the
column header, the row Headers and the data pane.


Nov 3, 2008 at 7:40 PM

You can do it by placing different Context Menus in DataGridColumnHeaderStyle and DataGridRowHeaderStyle or even in control templates for those parts of DataGrid. It should work.

                             Thanks. Lena


Nov 13, 2008 at 4:33 PM
Edited Nov 14, 2008 at 3:07 PM
Can you please show us how to access this DataGridColumnHeaderStyle?

I am using 






    <toolkit:DataGridTextColumn IsReadOnly='True' Header="OrderTime" Width="Auto"




    Binding="{Binding Path = _strOrderTime}" >









    <toolkit:DataGridTextColumn IsReadOnly='True' Header="UserId" Width="Auto"




    Binding="{Binding Path = _UserID}" />




I want to provide a context menu on these two headers? how do i do this?




Nov 14, 2008 at 10:47 PM
DataGridColumn has a property HeaderStyle.  With that you can create a ContextMenu in the HeaderStyle.
Nov 18, 2008 at 2:29 PM

Thanks for the reply but I am not able to get the context menu. Can you pls let me know what could be the issue with following code snippet. Don't seem to get this to work.

This is the code snippet that I have used:

HeaderStyle="{Binding Path = ColumnHeaderStyle}" IsReadOnly='True' Header="OrderTime" Width="Auto" Binding="{Binding Path = _strOrderTime}" >

The Column Header Style:

and the data template for the column header:


From: vinsibal []
Sent: Friday, November 14, 2008 5:48 PM
To: Saste, Satyajit
Subject: Re: Datagrid: ContextMenu for Column and Row Headers [wpf:38919]

From: vinsibal

DataGridColumn has a property HeaderStyle. With that you can create a ContextMenu in the HeaderStyle.

Read the full discussion online <> .

To add a post to this discussion, reply to this email ( <[wpf:38919]> )

To start a new discussion for this project, email

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe <> on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

DISCLAIMER: This e-mail message and any attachments are intended solely for the use of the individual or entity to which it is addressed and may contain information that is confidential or legally privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and permanently delete this message and any attachments.
Jan 15, 2009 at 11:05 AM
Anyone? :-)
Jan 15, 2009 at 1:28 PM
Here is an example of setting the contextmenu through the ColumnHeaderStyle property:



<ContextMenu x:Key="cm_columnHeaderMenu">

<Style x:Key="DefaultColumnHeaderStyle" TargetType="{x:Type toolkit:DataGridColumnHeader}">
    <Setter Property="ContextMenu" Value="{StaticResource cm_columnHeaderMenu}" />

<toolkit:DataGrid ColumnHeaderStyle="{StaticResource DefaultColumnHeaderStyle}">...


Mar 21, 2009 at 10:44 PM
I am trying to set the ContextMenu to cell so I can (or not?) now what column & row was the context menu called from.

I tried:
















<Setter Property="ContextMenu" Value="{StaticResource mnuContext}"/>



















But I get an error:
Error 1 Value 'ContextMenu' cannot be assigned to property 'Property'. Invalid PropertyDescriptor value. E:\WpfProjects\BssExpeditor\BssExpeditor\Pages\EmployeesPage.xaml 25 29 BssExpeditor




Mar 23, 2009 at 9:05 AM
Try this: