Context Menu for Column Headers in datagrid

Nov 14, 2008 at 3:09 PM
Can you please show us how to access the DataGridColumnHeaderStyle?
I want to provide a context menu on these two headers? how do i do this?
I am using the following code snippet:

 

<toolkit:DataGrid.Columns
    <toolkit:DataGridTextColumn IsReadOnly='True' Header="OrderTime" Width="Auto"   Binding="{Binding Path = _strOrderTime}" >     </toolkit:DataGridTextColumn
 
    <toolkit:DataGridTextColumn IsReadOnly='True' Header="UserId" Width="Auto"  Binding="{Binding Path = _UserID}" />
</toolkit:DataGrid.Columns>

Nov 18, 2008 at 2:29 PM

Hi,
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:

<toolkit:DataGrid.Columns>
      
<toolkit:DataGridTextColumn HeaderStyle="{Binding Path = ColumnHeaderStyle}" IsReadOnly='True' Header="OrderTime" Width="Auto"  Binding="{Binding  Path   =  _strOrderTime}" >
</toolkit:DataGridTextColumn>


The Column Header Style:

<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type toolkit:DataGridColumnHeader}" BasedOn="{StaticResource {x:Type toolkit:DataGridColumnHeader}}">

<Setter Property="Background" Value="{StaticResource DataGrid_Style0_Header}" />

<Setter Property="Foreground" Value="White" />

<Setter Property="HorizontalContentAlignment" Value="Center" />

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

and the data template for the column header:

<DataTemplate x:Key="MyContextMenuDataTemplate">

    <ContextMenu Name="test">

            <Menu Name="colMenu">

            <MenuItem Name="temp" Header="temp"></MenuItem>

            </Menu>

    </ContextMenu>

</DataTemplate>

Coordinator
Nov 18, 2008 at 5:17 PM
DataGridColumnHeader.ContextMenu is of type ContextMenu, not DataTemplate.
Nov 18, 2008 at 6:19 PM
can you pls give some more explanation? Is there some
documentation for this grid. I could read and figure out.
Do you have some sample app or snippet that I can look at.
Any help would be appreciated...
Thanks.


From: vinsibal [mailto:notifications@codeplex.com]
Sent: Tuesday, November 18, 2008 12:18 PM
To: Saste, Satyajit
Subject: Re: Context Menu for Column Headers in datagrid [wpf:39956]

From: vinsibal

DataGridColumnHeader.ContextMenu is of type ContextMenu, not DataTemplate.
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.