OpenClipboard当从wpf DataGrid复制粘贴数据时失败 [英] OpenClipboard Failed when copy pasting data from wpf DataGrid

查看:808
本文介绍了OpenClipboard当从wpf DataGrid复制粘贴数据时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序使用datagrid。该应用程序运行正常,直到我安装了VS2012和Blend + SketchFlow预览。现在,当我尝试使用ctrl + C(任何应用程序)将格网中的数据复制到剪贴板时,我得到以下异常:

  System.Runtime.InteropServices.COMException(0x800401D0):OpenClipboard Failed(来自HRESULT的异常:0x800401D0(CLIPBRD_E_CANT_OPEN))
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo)
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode,IntPtr errorInfo)
在System.Windows.Clipboard.Flush()
在System.Windows.Clipboard.CriticalSetDataObject(对象数据,布尔复制)
在System.Windows.Controls.DataGrid.OnExecutedCopy(ExecutedRoutedEventArgs args)
在System.Windows.Controls.DataGrid.OnExecutedCopy(Object target,ExecutedRoutedEventArgs args)
at System.Windows.Input.CommandBinding.OnExecuted(Object sender,ExecutedRoutedEventArgs e)
在System.Windows.Input.CommandManager.ExecuteCommand在System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings,Object sender,RoutedEventArgs e,ICommand命令,Boolean execute)中的Binding(Object sender,ExecutedRoutedEventArgs e,CommandBinding commandBinding)
。 Input.CommandManager.FindCommandBinding(Object sender,RoutedEventArgs e,ICommand命令,Boolean execute)
在System.Windows.Input.CommandManager.OnExecuted(Object sender,ExecutedRoutedEventArgs e)
在System.Windows.UIElement。 OnExecutedThunk(Object sender,ExecutedRoutedEventArgs e)
在System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(Delegate genericHandler,Object target)
在System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler,Object target)
在System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target,RoutedEventArgs routedEventArgs)
在System.Windows.EventRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boole一个reRaised)
在System.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)
在System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
在System.Windows.UIElement.RaiseEvent (RoutedEventArgs args,Boolean trusted)
在System.Windows.Input.RoutedCommand.ExecuteImpl(Object参数,IInputElement target,Boolean userInitiated)
在System.Windows.Input.RoutedCommand.ExecuteCore(Object参数,IInputElement目标,布尔userInitiated)
在System.Windows.Input.CommandManager.TranslateInput(IInputElement targetElement,InputEventArgs inputEventArgs)
在System.Windows.UIElement.OnKeyDownThunk(对象发件人,KeyEventArgs e)
在System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget)
在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)
在System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,呃tedEventArgs routedEventArgs)
在System.Windows.EventRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boolean reRaised)
在System.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)
在系统.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
在System.Windows.UIElement.RaiseEvent(RoutedEventArgs args,Boolean trusted)
在System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
在System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
在System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd,InputMode模式,Int32时间戳记,RawKeyboardActions动作,Int32 scanCode,Boolean isExtendedKey,Boolean isSystemKey,Int32 virtualKey)
在System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg,Boolean&处理)
在System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg,ModifierKeys修饰符)
在System.Windows.Interop.HwndSource.OnPreprocessMessage(对象参数)
在System.Windows .Threading.ExceptionWrapper.InternalRealCall(Delegate callback,Object args,Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate method,Object args,Int32 numArgs,Delegate catchHandler)
在System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority优先级,TimeSpan超时,委托方法,对象args,Int32 numArgs)
在System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority优先级,委托方法,对象arg)
在System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg,Boolean&被处理)
在System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg,布尔&被处理)
在System.Windows.Inte rop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher System.Windows.Application.RunDispatcher(Object ignore)中的
$ System.Windows.Application.RunInternal(窗口窗口)中的
$ System.Windows.Application.Run(窗口)中的
窗口)
在System.Windows.Application.Run()

这真的很讨厌。



我看到一些这个问题的引用这里和网络上的各种位置,没有真正的解决方案。



我可以验证剪贴板是否被锁定,当这个异常在视觉工作室中升起,因为我无法复制粘贴消息(不得不将其写入文件)。此外,在复制过程开始之前,剪贴板没有被锁定。



有没有人有这个问题并解决了?

解决方案

我们正在使用.NET 4.0。我们有同样的问题,但是在注销系统后,代码用于工作一段时间。
最后找到了替代方案。



如果要在剪贴板上复制字符串

 字符串数据=复制此

到目前为止,我使用以下方法

  Clipboard.SetText(data); 

它一次又一次失败。然后,我查看了其他可用于在剪贴板中设置文本的方法,其中包括 http: //msdn.microsoft.com/en-IN/library/system.windows.clipboard.aspx
并尝试以下

  Clipboard.SetDataObject(data); 

和IT工作:)。从未再次出现问题。


I've got a WPF app using datagrid. The app worked fine until I installed VS2012 and Blend+SketchFlow preview. Now, when I'm trying to copy the data from the grid into the clipboard with ctrl+C (in any app), I'm getting following exception:

System.Runtime.InteropServices.COMException (0x800401D0): OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
   at System.Windows.Clipboard.Flush()
   at System.Windows.Clipboard.CriticalSetDataObject(Object data, Boolean copy)
   at System.Windows.Controls.DataGrid.OnExecutedCopy(ExecutedRoutedEventArgs args)
   at System.Windows.Controls.DataGrid.OnExecutedCopy(Object target, ExecutedRoutedEventArgs args)
   at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
   at System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at System.Windows.UIElement.OnExecutedThunk(Object sender, ExecutedRoutedEventArgs e)
   at System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated)
   at System.Windows.Input.RoutedCommand.ExecuteCore(Object parameter, IInputElement target, Boolean userInitiated)
   at System.Windows.Input.CommandManager.TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
   at System.Windows.UIElement.OnKeyDownThunk(Object sender, KeyEventArgs e)
   at System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled)
   at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()

This is really annoying.

I've seen some references to this problem here and on various locations on the web, with no real solution.

I can verify that the clipboard is locked when this exception is raised in visual studio, as I couldn't copy paste the message (had to write it to a file). Also, the clipboard wasn't locked before the copy process started.

Had anybody here have this problem and solved it?

解决方案

We are using .NET 4.0. We had the same problem but after logging off the system, code used to work fine for sometime. Finally found the alternative.

If you want to copy a string on clipboard

string data = "Copy This"

Till now I was using following method

Clipboard.SetText(data);

It was failing again and again. Then I looked at other methods available to set text in clipboard at http://msdn.microsoft.com/en-IN/library/system.windows.clipboard.aspx and tried following

Clipboard.SetDataObject(data);

and IT worked :). Never had issue again.

这篇关于OpenClipboard当从wpf DataGrid复制粘贴数据时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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