zoukankan      html  css  js  c++  java
  • WPF 中 OpenClipboard 失败问题

    解决方案可以参照:https://stackoverflow.com/questions/12769264/openclipboard-failed-when-copy-pasting-data-from-wpf-datagrid

    关键的问题在于 Clipboard.SetText() 方法会触发异常。

    方案一:

    It is a bug in the WPF Clipboard handler. You need to handle the unhandled exception in the Application.DispatcherUnhandledException event.

    Add this attribute to the Application element in your App.xaml

    DispatcherUnhandledException="Application_DispatcherUnhandledException"

    Add this code to your App.xaml.cs file

    void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        var comException = e.Exception as System.Runtime.InteropServices.COMException;
    
        if (comException != null && comException.ErrorCode == -2147221040)
             e.Handled = true;
    }

    方案二:

    We are using .NET 4.0. We had the same problem, but after logging off the system, code used to work fine for some time.

    Finally we found the alternative.

    If you want to copy a string to the clipboard,

    string data = "Copy This"

    Till now I was using the following method

    Clipboard.SetText(data);

    It was failing again and again. Then I looked at other methods available to set text in the clipboard in Clipboard Class and tried the following:

    Clipboard.SetDataObject(data);

    And it worked :). I never had the issue again.

    更多的方案参照最上方的链接。

    如果是 DataGrid 的复制问题,一般 DataGridTextColumn 是可以直接进行复制的,如果是 DataGridTemplateColumn,则需要添加

    ClipboardContentBinding="{Binding 属性}"

    到 DataGridTemplateColumn 中就能解决此问题。

  • 相关阅读:
    论有一个服务器后可以干什么
    golang的安装后的文件目录解析
    使用go自带的http包搭建一个的web服务器
    python字符串问题—文件排版
    Python 整数的N进制字符串表示,循环和函数_亲密数,DNA匹配A
    mongodb 基本CRUD
    pip;python包管理工具
    STM32中assert_param的使用
    stm32.cube(一)——系统架构及目录结构
    HTTP、TCP、UDP,Socket,HTTPS
  • 原文地址:https://www.cnblogs.com/xiefang2008/p/7703716.html
Copyright © 2011-2022 走看看