Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Copy from a DataGrid

I would like to add Copy functionality to a WPF DataGrid.

  1. The Copy option should appear in a right-click menu
  2. It should copy the display text for the selected cell. (I am using read-only text columns.)
like image 799
Jonathan Allen Avatar asked Sep 29 '10 19:09

Jonathan Allen


1 Answers

In the DataGrid's ContextMenu, you can create a MenuItem and set the MenuItem.Command value to Copy. It's a Command available through the standard ApplicationCommands list, so there won't be any additional code required to have it functional:

<DataGrid>
    <DataGrid.ContextMenu>
        <ContextMenu>
            <MenuItem Command="Copy" />
        </ContextMenu>
    </DataGrid.ContextMenu>
</DataGrid>
like image 66
newfurniturey Avatar answered Oct 08 '22 16:10

newfurniturey