Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to use keyDonw event to implement Copy and Paste ? (Read 2756 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to use keyDonw event to implement Copy and Paste ?
Mar 4th, 2015 at 7:34am
Print Post  
hi,
I use KeyDown like this:
Code
Select All
    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.C)
    {
        CopyItems();
    }
    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.V)
    {
        PasteItems();
    }
 


but, it never execute the CopyItems and PasteItems method?
do the Diagram have handled the Ctrl-Key?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use keyDonw event to implement Copy and Paste ?
Reply #1 - Mar 4th, 2015 at 8:27am
Print Post  
Hi,

WPF executes ApplicationCommands.Copy / Paste for these key combinations, and the diagram handles them by calling its CopyToClipboard and PasteFromClipboard methods. If you want to use your methods instead, you can override the diagram handlers like this:

Code
Select All
diagram.CommandBindings.Add(
	new CommandBinding(ApplicationCommands.Copy, (sender, args) => CopyItems())); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use keyDonw event to implement Copy and Paste ?
Reply #2 - Mar 4th, 2015 at 9:02am
Print Post  
hi Stoyan,
  my CopyItems and PasteItems has no parameter, so I can't use your code.
  

effect_004.png ( 16 KB | 67 Downloads )
effect_004.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use keyDonw event to implement Copy and Paste ?
Reply #3 - Mar 4th, 2015 at 10:35am
Print Post  
My code also calls CopyItems() without arguments if you look above, I don't know why you have added ones. The (sender,args) parameters are for the lambda expression set as handler of Copy command and you can ignore them, you don't have to pass them to CopyItems. If you have a 'sender' argument passed to outer method from where you call Bindings.Add, you'll only have to rename the inner one, e.g. call it just 's'.
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use keyDonw event to implement Copy and Paste ?
Reply #4 - Mar 5th, 2015 at 1:51am
Print Post  
hi Stoyan,
I have fixed my errors using below code.
But when I move some of nodes on Diagram.It trigger CustomerCopyItems method everytime.
is there some properties of Diagram which I have not setted its value?
thanks.
Code
Select All
 void CustomerCopyItems(object sender, ExecutedRoutedEventArgs e)
 {
     CopyItems();
 }
void CustomerPasteItems(object sender, ExecutedRoutedEventArgs e)
 {
     PasteItems();
 }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use keyDonw event to implement Copy and Paste ?
Reply #5 - Mar 5th, 2015 at 9:06am
Print Post  
Hi,

The diagram won't call your methods on its own. Check if you aren't calling them from some event handlers, such us OnMouseButtonUp or OnNodeModified. E.g. add breakpoints on the CopyItems() and PasteItems() lines, and see what other methods are shown in the call-stack window when the breakpoints hit.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint