【发布时间】:2019-07-15 02:39:57
【问题描述】:
当我在 DataGrid 中按 Ctrl + C 时,我希望能够复制一个单元格而不是一行,我发现我可以使用事件 CopyingRowClipboardContent 和处理程序来做到这一点:
Private Sub DataGrid_CopyingRowClipboardContent(ByVal sender As Object, ByVal e As DataGridRowClipboardEventArgs)
Dim currentCell = e.ClipboardRowContent(dataGrid.CurrentCell.Column.DisplayIndex)
e.ClipboardRowContent.Clear()
e.ClipboardRowContent.Add(currentCell)
End Sub
我想将此行为全局分配给在运行时创建的任何 DataGrid(而不是返回我的代码并将处理程序一一添加到所有 DataGrid)。
我尝试将以下行添加到我的 <Window.Resources> 代码中:
<Style x:Key="DataGridCustomStyle" TargetType="{x:Type DataGrid}">
<EventSetter Event="CopyingRowClipboardContent" Handler="Datagrid_CopyingRowClipboardContent" />
</Style>
但我收到一条错误消息,提示 CopyingRowClipboardContent 必须是 RoutedEvent 事件。
【问题讨论】:
-
我面临同样的问题。你有没有让它工作?
-
@RafaGomez 不幸的是没有。
标签: wpf vb.net visual-studio-2010