在我的 WPF 应用程序中,我使用 Datagrid
控件;在控件定义中,我将 ClipboardCopyMode
属性定义为“IncludeHeader”。
<DataGrid Name="datagrid" ClipboardCopyMode="IncludeHeader">
</DataGrid>
有时,当我尝试从网格复制任何数据时,会遇到 HRESULT
剪贴板崩溃错误 -
System.Runtime.InteropServices.COMException (0x800401D0):
OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))
任何解决该问题的建议。我查看了其他帖子,大部分都是关于当您显式使用 Clipboard
相关方法时如何处理这种情况,但没有与 Datagrid
相关。
最佳答案
从安德鲁·史密斯那里找到了这个:http://blogs.infragistics.com/forums/t/35379.aspx -
Technically only 1 process can open the clipboard so if another process has it opened the subsequent requests will fail until the first releases the clipboard. This was sort of handled in the WinForms Clipboard class where it would retry the set with a delay in between each try but the WPF clipboard class doesn't do this so if it fails on the first show the exception occurs. Even then we should probably catch the exception and raise the clipboard operation error if it still fails.
这个意大利博客解释了同样的事情,并提到了一些修复它的方法 -
以下 MSDN 论坛主题表明这可能是机器特定的问题,您可以在其他机器上重现此问题吗? -
CLIPBRD_E_CANT_OPEN exception when copying to clipboard from a DataGrid
更新:
博客链接似乎已关闭,但可以通过此链接访问缓存版本 -
关于.net - 使用 IncludeHeader ClipboardCopyMode 时出现 WPF Datagrid COMException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10855940/