Handling copy paste from Button click


I have a diagram and some nodes in the palette. I drag few nodes on to the diagram. I select them and I press Ctrl+C and Ctrl+V the selected nodes got pasted on to the diagram which is perfect.

Now, I want to achieve the same scenarios using button click. i.e. I drag and drop the nodes from palette on to the diagram and I click on copy button and it should copy to the clipboard and when I click on the paste button it should paste to the selected instance of diagram. I have used ClipboardPasted and SelectionCopied events to bind ( via Commands) but seems to be not working.

Also I tried to use the default commands from WPF i.e. Copy Paste Undo Redo etc for menuitem instance. this also worked perfectly. But I would have to do some custom operations before Copy paste events. Hence we have to hook button commands to the diagram events.

Suggestion awaited.

I’m not clear about what you want to do, but you could try overriding methods of CommandHandler:

Or if you wanted to change or extend how the selection is saved, override:

Thanks for the references Walter. How Can I bind these Commands to my button ?

There are routed Commands that are static properties of the Commands class:

Actually, those two are exactly the same object as ApplicationCommands.Copy and ApplicationCommands.Paste, as are some of the other “standard” commands. All commands eventually get handled by the CommandHandler.

Okay. I was earlier using the same Commands i.e. ApplicationCommand.Copy etc but found that these commands work only with MenuItem control and not any other control. Hence I have to find a way to do Copy - Paste - Undo - Redo and such events from button click. How can we do that using GoXam commands/events.

I have to manually call the corresponding goxam event when my copy button is clicked. but not sure how do I pass the parameters to that event.

I am using MVVM in my project.

Are you asking for something like this:

<Button Command="Paste" CommandTarget="{Binding ElementName=myDiagram}">Paste</Button>