【问题标题】:Ctrl+C not copying to Clipboard for WPF DataGridCtrl+C 不复制到 WPF DataGrid 的剪贴板
【发布时间】:2016-08-18 20:38:49
【问题描述】:

我正在使用下面定义的标准数据网格。一些计算完成后,itemssource绑定在后面的代码中。

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

我遇到的问题与复制数据有关。当我 ctrl+A 选择所有单元格并右键单击,复制时,它将选择数据并将其添加到剪贴板。但是,如果我使用 ctrl+c,则不会将任何内容放入剪贴板。

这是我第一次在这里发帖,我已经阅读了几乎所有建议,从最简单的应用程序命令添加到修改 oncopytoclipboard 类型事件,似乎没有任何效果。我觉得我错过了一些应该很明显的东西。

感谢任何可以提供帮助的人。

【问题讨论】:

  • 看看这是否有帮助:stackoverflow.com/a/12943306
  • 您需要确保您的键盘焦点位于您想要的位置。我不确定那是怎么回事。但我 100% 确定这与键盘焦点所在的位置有关。
  • 射击。两者似乎都无法解决问题。即使设置了键盘焦点,仍然没有任何内容发送到剪贴板

标签: c# wpf datagrid


【解决方案1】:

试试这个:

<!-- 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>

【讨论】:

    猜你喜欢
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多