Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
720
XamGrid CopyToClipboard fails when notepad++ is open
posted

Hi

I have implemented the XamGrid copy to clipboard operation using the XamGrid.CopyToClipboard method. The method works fine if I do not have notepad++ open. If its open and if I try a copy using Ctrl+C then it fails with the following error.

OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN)) ErrorCode:-2147221040

Kindly let me know what can be done. Also, please note that I cannot add any App.xaml code handlers because I cannot change that file.

Thanks

Chev

Parents
  • 6759
    Offline posted

    Hi Chev,

    I've tested similar scenario and was not able to reproduce this issue.  Could you please provide a sample project where it is easily reproducible?

    Are you reproducing this consistently(for every invoke of XamGrid.CopyToClipboard() when the notepad++ is running)? Such an exception usually occurs during concurrent access to the clipboard. Is it happening when you try to copy text from a TextBox for example? Do you have any notepad++ plugins that are doing something with the clipboard ?

    As a workaround you could wrap the XamGrid.CopyToClipboard() method in try catch and look for COMException - if such an exception is thrown the best solution is to add a short wait(I suppose few milliseconds would be enough) and try again(and probably make few more trials) - if it is still failing most probably some other application has opened the clipboard and kept it open for quite some time.

Reply Children