.net - 使用 IncludeHeader ClipboardCopyMode 时出现 WPF Datagrid COMException

标签 .net wpf wpfdatagrid clipboard

在我的 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.

这个意大利博客解释了同样的事情,并提到了一些修复它的方法 -

WPF DataGrid Clipboard BUG (?) & Work

Google Translation

以下 MSDN 论坛主题表明这可能是机器特定的问题,您可以在其他机器上重现此问题吗? -

CLIPBRD_E_CANT_OPEN exception when copying to clipboard from a DataGrid

更新:

博客链接似乎已关闭,但可以通过此链接访问缓存版本 -

WPF DataGrid Clipboard BUG (?) & Work (Cached translation)

关于.net - 使用 IncludeHeader ClipboardCopyMode 时出现 WPF Datagrid COMException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10855940/

相关文章:

.net - Azure Web 角色如何在没有入口点的情况下运行?

c# - XAML 中的对象初始值设定项

wpf - Datagrid 行的静态数据是否可以纯粹在 XAML 中定义,即没有代码背后?

wpf - 如何提高 WPF 网格控件 (.NET 4.0/4.5) 的性能?

wpf - 在文本框上过滤 DataGrid

.net - WPF MVVM + UserControl 与后面的代码

C# 静态垃圾收集器?

c# - 将自定义 EventArgs 作为事件参数传递

c# - WPF 导航和旋转背景

wpf - 在 View 或 View 模型中订购元素?