WPF DataGrid复制单元格问题

当复制出现 以下错误时:System.Runtime.InteropServices.COMException (0x800401D0),这是在WPF剪贴板程序错误。


解决方法:则在需要在App.xaml.cs添加以下代码
    private 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;
            }
     
        }
一般是DataGridTextColumn是可以直接复制,如果是DataGridTemplateColumn,则需要在添加   ClipboardContentBinding="{Binding 绑定的属性}"
DataGridTemplateColumn中.

 

 
posted @ 2017-04-07 09:40  fishyue  阅读(3329)  评论(0编辑  收藏  举报