WPF的Datagrid收到COMException使用IncludeHeader ClipboardCopyModeDatagrid、WPF、COMException、ClipboardCopyMo

2023-09-04 23:47:30 作者:嫑臉.

在我的WPF应用程序,我使用的是的Datagrid 控制;在控制定义我定义的 ClipboardCopyMode 属性为IncludeHeader。

In my WPF app, I am using a Datagrid control; in the control definition I defined ClipboardCopyMode property as 'IncludeHeader'.

<DataGrid Name="datagrid"  ClipboardCopyMode="IncludeHeader">
</DataGrid>

有时,当我尝试,我遇到复制从电网的任何数据 HRESULT 剪贴板崩溃的错误 -

At times, when I try to copy any data from grid, I am encountering HRESULT clipboard crash error -

System.Runtime.InteropServices.COMException (0x800401D0): 
OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))

任何建议,以解决这个问题。我看了看其他的帖子,大多是一些有关如何处理这种情况,当你明确地使用剪贴板相关方法,但没有涉及到的Datagrid

Any suggestions to resolve it. I looked at other posts, mostly they are about how to handle this scenario when you explicitly use the Clipboard related methods but none related to Datagrid.

推荐答案

从安德鲁·史密斯发现这个在的 http://blogs.infragistics.com/forums/t/35379.aspx -

Found this from Andrew Smith at http://blogs.infragistics.com/forums/t/35379.aspx -

从技术上讲只有1个程序可以打开剪贴板,所以如果另一   进程把它打开了后续请求将失败,直到   首先发布剪贴板。排序这是在WinForms的处理   Clipboard类哪里会重试与集之间的延迟   每一个尝试,但这样如果失败的WPF剪贴板类不这样做   首秀的异常发生。即使这样,我们或许应该   捕获异常,提高剪贴板操作错误,如果它   仍然失败。

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.

同样的事情,解释和一些方法来解决它提到在这个意大利博客 -

Same thing is explained and some ways to fix it are mentioned on this italian blog -

WPF的DataGrid剪贴板BUG&AMP(?);工作

谷歌翻译

下面的MSDN论坛帖子表明,这可能是该机的具体问题,你可以重现这个在其他机器? -

Following MSDN forum thread suggests that this could be machine specific problem, can you reproduce this on other machines? -

CLIPBRD_E_CANT_OPEN异常从   数据网格

CLIPBRD_E_CANT_OPEN exception when copying to clipboard from a DataGrid

更新:

博客链接似乎是下降,但高速缓存的版本可以通过这个链接访问 -

Blog link seems to be down but a cached version can be accessed through this link -

WPF的DataGrid剪贴板BUG&AMP(?);工作(缓存译)