Skip to content

How to set different DataGridColumnHeader has different ContextMenu? #17743

Answered by msneijders
nasterhe asked this question in Q&A
Discussion options

You must be logged in to vote

Alternative way, if your header content is a constant:

<DataGrid>
   <DataGrid.Styles>
     <Style Selector="DataGridColumnHeader[Content=Area]">
        <Setter Property="ContextMenu">
           <ContextMenu>
               <MenuItem Header="ContextMenu of column Area" />
            </ContextMenu>
         </Setter>
      </Style>
   </DataGrid.Styles>
</DataGrid>

Possible a custom handling of Control.ContextRequestedEvent could help as well -- but I do not see a reliable way of identifying which header is clicked, other then checking the header text, as most information about it is marked internal.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@msneijders
Comment options

Answer selected by nasterhe
@nasterhe
Comment options

Comment options

You must be logged in to vote
2 replies
@msneijders
Comment options

@nasterhe
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants