locked
Adding a ContextMenu to a DataGridTextColumn RRS feed

  • Question

  • Hi,

    Using the following approach I've been able to successfully add a ContextMenu to a DataGridTemplateColumn: -

    <dg:DataGridTemplateColumn Header="Description">
    	<dg:DataGridTemplateColumn.CellTemplate>
    		<DataTemplate>
    			<TextBlock Text="{Binding Description}" Margin="4">
    				<toolkit:ContextMenuService.ContextMenu>
    					<toolkit:ContextMenu>
    						<toolkit:MenuItem Header="Delete" Click="Delete_Click"/>
    					</toolkit:ContextMenu>
    				</toolkit:ContextMenuService.ContextMenu>
    			</TextBlock>
    		</DataTemplate>
    	</dg:DataGridTemplateColumn.CellTemplate>
    </dg:DataGridTemplateColumn>
    

    However, I'd like to add the same ContextMenu to a DataGridTextColumn. 

    Is this possible and, if so, what is the appropriate approach?

    Thanks in advance,

    Chris

    Sunday, August 22, 2010 9:56 AM

Answers

  • Hi,

    I'm afraid the answer is: no, you cannot add a contextmenu to a DataGridTextColumn, because it's not a FrameworkElement. Instead, you have an option to use a DataGridTemplateColumn with TextBlock as CellTemplate and TextBox as CellEditingTemplate, just as you did already. 

    Tuesday, August 24, 2010 1:27 AM

All replies

  • Hi,

    I'm afraid the answer is: no, you cannot add a contextmenu to a DataGridTextColumn, because it's not a FrameworkElement. Instead, you have an option to use a DataGridTemplateColumn with TextBlock as CellTemplate and TextBox as CellEditingTemplate, just as you did already. 

    Tuesday, August 24, 2010 1:27 AM
  • Thanks for the answer – though I feared this was the case.

    I had hoped to use the ShortName DisplayAttribute to drive my column headings.  Unfortunately, as I understand the ShortName attribute isn't honoured by DataGridTemplateColumns, I'll have to scrap this idea if I need ContextMenus :(

     

    Thursday, August 26, 2010 3:43 PM