7
votes

I have a TextBox in CellEdititngTemplate for DataGridTemplateColumn in my DataGrid and I want to show 4 context menu items (Cut, Copy, Paste, Select All) when my DatagridCell is in edit mode and user right-clicks on it.

I see that default right-click context menu for TextBox control contains only 3 menu items: Cut (Ctrl+X), Copy (Ctrl+C), Paste (Ctrl+V).

There's no 'Select All' context menu item though Ctrl+A works for TextBox. So the question is - how to add a new Context Menu item 'Select All' into TextBox context menu without loosing cut, copy, paste menu items and their functionality?

2

2 Answers

12
votes

I don't think you can change existing context menu, but you can create yours and repeat other commands

<ContextMenu>
     <MenuItem Command="ApplicationCommands.Cut" />
     <MenuItem Command="ApplicationCommands.Copy" />
     <MenuItem Command="ApplicationCommands.Paste" />
     <MenuItem Command="ApplicationCommands.SelectAll" />
</ContextMenu>
0
votes

Usually I see a separator between the clipboard items and Select All. This worked for me in a RichTextBox:

            <FrameworkElement.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{x:Static ApplicationCommands.Cut}" />
                    <MenuItem Command="{x:Static ApplicationCommands.Copy}" />
                    <MenuItem Command="{x:Static ApplicationCommands.Paste}" />
                    <Separator />
                    <MenuItem Command="{x:Static ApplicationCommands.SelectAll}" />
                </ContextMenu>
            </FrameworkElement.ContextMenu>