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

Override keyboard copy/paste controls

2 Answers 491 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Zak
Top achievements
Rank 1
Zak asked on 11 Aug 2014, 03:32 PM
Hello,

I'd like to override the keyboard shortcuts for copy, cut and paste because there are some very specific things that I need to do to copy/paste my objects. I've tried overriding the OnKeyDown event, but the commands never hit that method, even though other ctrl commands (ex. ctrl+s) do. Is there a way to have this this control returned to me when I set AllowCopy, AllowCut and AllowPaste to False?

Thanks,
Zak

2 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 12 Aug 2014, 10:19 AM
Hi Zak,
Could you please elaborate a little bit more on what exactly are you trying to achieve ? There are a couple of ways to override the default copy, cut and paste commands but it depends on your specific scenario:
1) You could add your own command binding for those commands:
static Example()
{
    var copyBinding = new CommandBinding(DiagramCommands.Copy, OnCopyExecute, OnCanCopy);
    CommandManager.RegisterClassCommandBinding(typeof(RadDiagram), copyBinding);
}
 
private static void OnCanCopy(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
    e.Handled = true;
}
 
private static void OnCopyExecute(object sender, ExecutedRoutedEventArgs e)
{
    // Do what you want.
}
2) You could override the Ctr + C (Ctr + V and Ctr + X) input bindings with an ApplicationCommands.NotACommand and this way they will be ignored and the key down events will be rised:
public Example()
{
    InitializeComponent();
    CommandManager.RegisterClassInputBinding(typeof(RadDiagram), new InputBinding(ApplicationCommands.NotACommand, new KeyGesture(Key.C, ModifierKeys.Control)));
I hope I was able to help you and if you have more questions feel free to ask.

Regards,
Zarko
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Zak
Top achievements
Rank 1
answered on 12 Aug 2014, 02:17 PM
Those worked perfectly! Thank you very much!
Tags
Diagram
Asked by
Zak
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Zak
Top achievements
Rank 1
Share this question
or