WPF: Copy from a DataGrid

痴心易碎 提交于 2019-12-22 04:02:42

问题


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.)

回答1:


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>


来源:https://stackoverflow.com/questions/3825339/wpf-copy-from-a-datagrid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!