Hi,
We having a problem when trying to use the Clipboard in our Xaml application with enabled Clipboard copy functionality. The clipboard functionality works perfectly fine on any other hardware, however the failing ones are virtual PC's with installed VMWare application (provided by VMWare Horizon Client) limiting the clipboard access due policies. Here is a stack trace:
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.Windows.Clipboard.Flush() at System.Windows.Clipboard.CriticalSetDataObject(Object data, Boolean copy) at System.Windows.Clipboard.SetDataInternal(String format, Object data) at System.Windows.Clipboard.SetText(String text, TextDataFormat format) at Infragistics.Controls.Editors.ClipboardManager.SetText(String text) at Infragistics.Controls.Editors.ViewSelectionManager.Copy() at Infragistics.Controls.Editors.ViewKeyboardHandler.OnKeyDown(KeyEventArgs& e) at Infragistics.Controls.Editors.Primitives.EditorDocumentViewPresenter.OnKeyDown(KeyEventArgs e) 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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
We have tried various combinations with clipboard sample application and we face same problem when we try to use Clipboard.SetText(). However, we found a workaround for this error to use Clipboard.SetDataObject(object) for text and this works without any exception. Is there any chance to enhance logic to cover for Xaml to handle this at Infragistics side?
However, based on our tests it looks like this approach is affecting paste and application is hanging. We enabled in various places copy functionality like this:
<igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings SelectionTypeCell="Range" AllowClipboardOperations="Copy" CopyFieldLabelsToClipboard="True" SelectionTypeRecord="Extended" ...../> </igDP:XamDataGrid.FieldLayoutSettings>
Any suggestions on this topic?
best regards,
Tomas
Hi Andrew,
Our team has suggested to have other approach: to catch and ignore this error message. However, I see a problem here that this message comes from Infragistics and not from our side. How it is possible to customize the messages raised by Infragistics?
PresentationFramework.dll!System.Windows.MessageBox.ShowCore(System.IntPtr owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult, System.Windows.MessageBoxOptions options) Unknown PresentationFramework.dll!System.Windows.MessageBox.Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult) Unknown InfragisticsWPF.dll!Infragistics.Windows.Utilities.ShowMessageBox(System.Windows.DependencyObject element, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.Core.SpreadsheetUtilities.ShowMessageBox(System.Windows.FrameworkElement associatedControl, string message, string caption, System.Windows.MessageBoxButton buttons, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.XamSpreadsheet.Infragistics.Controls.Grids.Core.ISpreadsheetView.ShowMessageBox(string message, string caption, System.Windows.MessageBoxButton buttons, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.Core.Spreadsheet.OnUserPrompt(Infragistics.Controls.Grids.Core.SpreadsheetUserPromptInfo promptInfo) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.Core.Spreadsheet.CopyToClipboard.AnonymousMethod__265_4(object o, Infragistics.Controls.Grids.Core.WorkbookSerializationErrorEventArgs e) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.Core.WorkbookDataObjectManager.RaiseSerializationError(bool isLoading, System.Exception exception) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.Core.WorkbookDataObjectManager.CopyToClipboard(System.Func<bool> shouldProcessLargeCellCount) Unknown InfragisticsWPF.Controls.Grids.XamSpreadsheet.dll!Infragistics.Controls.Grids.Core.Spreadsheet.CopyToClipboard(bool cut) Unknown
We should be able to customize all Infragistics shown messages. If this is not possible then we would request to have ability since this is not the first message we see but we can't even control or change it. Not to mention that text is misleading: on copy says error on paste.
Hello Tomas,
Thank you for confirming that you are using the XamDataGrid, XamSpreadsheet, and XamSyntaxEditor and that you are targeting .NET 6.
Regarding copying text from the XamDataGrid, the best thing I can recommend is to utilize the SelectedItems collection of the grid. This collection has Records and Cells sub-collections that can return you the selected rows or cells. The XamSpreadsheet can be retrieved using its ActiveSelection property.
Regarding the XamSyntaxEditor, I believe the best option would likely be to utilize the ClipboardOperationExecuting/Executed events. The event arguments will return you the type of operation that is executing as well as the data object that is being copied in the case of the Copy clipboard operation.
Please let me know if you have any other questions or concerns on this matter.
Hello Andrew,
Sorry for confusion, we are using xamDataGrid and not GridView. With regards mentioned controls - we use most of time xamSpreadhsheet and xamSyntaxEditor for clipboard actions. The xamDataGrid is less used but it is enabled in few places for copy only. We will have to discuss with team and product owners to make decision on next actions.
The .NET 6 is our target. However, we have a huge challenge since we provide lots of products which are incorporated to work together very tightly, thus this challenge is very high and fragile to make it backwards compatible with all other products since upgrade for some products is slow and for some is quick. Not to mention that we are still using unsupported in .NET WCF as well as depended on few third party libraries. So upgrade wont be fast but first step is planned for next year.
I noticed in your most recent update that you mentioned a “XamGridView” – if at all possible I would recommend upgrading to the XamDataGrid if you are not using it already. The XamGrid is a retired and unsupported control at this point and has been marked obsolete to the XamDataGrid.
Regarding a workaround for this behavior though, I am unsure if the ViewSelectionManager will really help you in this case. The ViewSelectionManager is a public class, but it is used with the XamRichTextEditor and XamSyntaxEditor for copying and pasting text in those controls – it will not help you with cell-based controls like the XamSpreadsheet and XamDataGrid. The ClipboardManager is an internal class and so is not publicly accessible.
Both the XamSpreadsheet and XamDataGrid do expose ways to get the current selected cells though. The XamSpreadsheet through its ActiveSelection property and the XamDataGrid through its SelectedItems collection. My best recommendation would be to utilize these to construct the item that should go to the clipboard.
It’s also worth noting that most of the occurrences of this error seem to be referenced in older forum threads from various sources. I am curious if perhaps this issue has been fixed in later versions of the .NET Framework or potentially .NET Core / .NET 5 / .NET 6. What version of .NET are you currently targeting?
Thanks for clarification. I was able to reproduce same clipboard problem with simple console application on virtual PC and this is really problem inside of .NET framework.
Considering a workaround to replace .NET clipboard functionality I've tried to access the Keyboard.FocusedElement to get text for setting clipboard value but I did not found a sample on stackoverflow how to create text from selected range of cells in xamGridview or xamSpreadsheet controls. Based on testing I see I can iterate all cells and grab labels with values and manually generate text. Is there any other quick way to create text for clipboard? I was expecting I could access to Infragistics.Controls.Editors.ClipboardManager or Infragistics.Controls.Editors.ViewSelectionManager to get text before setting the clipboard.