WPF DataGrid, Copy to Clipboard after Ctrl+C,OnCopyingRowClipboardContent

前端 未结 2 1513
走了就别回头了
走了就别回头了 2021-02-13 05:27

For WPF, Data Grid I am trying to copy to clipboard my custom text data, after Ctrl+C Diverse attempts to use override OnCopyingRowClipboardContent(DataGridRo

相关标签:
2条回答
  • 2021-02-13 06:19

    You need to set the ClipboardRowContent property of DataGridRowClipboardEventArgs

    static void dataGrid_CopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e)
    {
        e.ClipboardRowContent.Clear();
        e.ClipboardRowContent.Add(new DataGridClipboardCellContent(e.Item, (sender as DataGrid).Columns[0], "Abc-hello"));
    }
    
    0 讨论(0)
  • 2021-02-13 06:25

    the correct way is add on XAML grid this property

    ClipboardCopyMode="ExcludeHeader"
    

    and for each property you want copy add this XAML

     <DataGridTemplateColumn  ClipboardContentBinding="{Binding XXXXXX} ..... 
    

    other facultative step is implement the dataGrid event CopyingRowClipboardContent to modify the clipoard data

    0 讨论(0)
提交回复
热议问题