WPF DataGrid,Ctrl + C后复制到剪贴板,OnCopyingRowClipboardContent [英] WPF DataGrid, Copy to Clipboard after Ctrl+C,OnCopyingRowClipboardContent

查看:1829
本文介绍了WPF DataGrid,Ctrl + C后复制到剪贴板,OnCopyingRowClipboardContent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于WPF,数据网格我试图复制到剪贴板我的自定义文本数据,之后 Ctrl + C
不同的尝试使用覆盖
OnCopyingRowClipboardContent(DataGridRowClipboardEventArgs args) CopingRowClipboardContent事件,不要帮忙。剪贴板都是空的或标准的行文本,但不是我想放在那里。
例如

For WPF, Data Grid I am trying to copy to clipboard my custom text data, after Ctrl+C Diverse attempts to use override OnCopyingRowClipboardContent(DataGridRowClipboardEventArgs args) or CopingRowClipboardContent event, don't help. Either clipboard gets empty or standard row text, but not what I would like to put there. For instance

protected override void OnCopyingRowClipboardContent(DataGridRowClipboardEventArgs args)
{
    Clipboard.SetText("Abc-hello");
    bool b1 = Clipboard.ContainsText();
    string s1 = Clipboard.GetText();
}

s1 文本,但是出来之后,这个方法剪贴板变空。
任何想法如果可以解决这个问题?

s1 gets desired text, but after going out of this method clipboard gets empty. Any idea if one can solve this?

推荐答案

正确的方法是在XAML网格上添加此属性

the correct way is add on XAML grid this property

ClipboardCopyMode="ExcludeHeader"

,并为您要复制的每个属性添加此XAML

and for each property you want copy add this XAML

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

其他兼容性步骤是实现dataGrid事件CopyingRowClipboardContent来修改剪贴板数据

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

这篇关于WPF DataGrid,Ctrl + C后复制到剪贴板,OnCopyingRowClipboardContent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆