I'm using a standard data grid defined below. The itemssource is bound in the code behind after some calculations are done.
<DataGrid Name="TimeDataGrid" Block.TextAlignment="Center" FontSize="14" SelectionMode="Extended" SelectionUnit="Cell" ClipboardCopyMode="ExcludeHeader" AutoGeneratingColumn="OFMDataGrid_AutoGeneratingColumn">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Command="Copy"/>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.InputBindings>
<KeyBinding Key="C" Modifiers="Control" Command="Copy" />
</DataGrid.InputBindings>
</DataGrid>
The problem I am having is related to copying the data. When I ctrl+A to select all cells and the right-click, copy, it will select the data and add it to the clipboard. However, if I use ctrl+c, nothing gets put to the clipboard.
This is my first time posting here and I have read just about every suggestion ranging from the simplest adding of the applicationcommands to modifying oncopytoclipboard type events and nothing seems to work. I feel like I am missing something that should be obvious.
Thank you to anyone who can help.
Try this:
<!-- This is required to handle CTRL + C when something is selected in the DataGrid -->
<DataGrid.CommandBindings>
<CommandBinding Command="Copy" Executed="CopyCommand" />
</DataGrid.CommandBindings>
<!-- This is required to handle CTRL + C when something is selected in the DataGrid -->
<DataGrid.InputBindings>
<KeyBinding Key="C" Modifiers="Control" Command="Copy" />
</DataGrid.InputBindings>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.