This is a migrated thread and some comments may be shown as answers.

Overriding Ctrl-C copy to clipboard

1 Answer 537 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Jim Girling
Top achievements
Rank 1
Jim Girling asked on 26 Feb 2018, 03:24 PM

I am trying to override the default behaviour for copy to clipboard from the PDF control when invoked from the keyboard.

I've created a class derived from FixedDocumentViewerCommandBase to add my custom action and this works when invoked from the Telerik toolbar or default context menu but it doesn't get invoked from the keyboard shortcut Ctrl-C.

So I've tried calling KeyBindings.Clear and adding a new KeyBinding.  At first, I thought this had not worked at all - the default copy to clipboard was executed when I selected some text.  However, what actually seems to be going on is that the KeyBindings are reset to their defaults when Mode is switched to TextSelection.

Have I missed a trick here?

1 Answer, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 01 Mar 2018, 02:18 PM
Hello Chris Johnson,

In order to change the logic executed on Ctrl+C you could change the Command associated with the copy KeyBinding when the RadPdfViewer.Mode is changed to TextSelection:
private void PdfViewer_ModeChanged(object sender, EventArgs e)
{
    if (viewer.Mode == Telerik.Windows.Documents.Fixed.UI.FixedDocumentViewerMode.TextSelection)
    {
        foreach (KeyBinding binding in viewer.InputBindings)
        {
            if (binding.Key == Key.C)
            {
                binding.Command = <myNewCommand>;
            }
        }
    }
}
This is so, because this key binding is not present in Pan mode and is applied whenever the mode is changed to TextSelection (as you observed, when the mode is changed, the key bindings are reset).

I've prepared a sample project demonstrating this approach. Please find it attached.
Hope this helps.

Regards,
Polya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PDFViewer
Asked by
Jim Girling
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or