views:

31

answers:

1

Hi, well this is driving me crazy. We have a command like so:

<CommandBinding Command="ApplicationCommands.Paste" CanExecute="HasClipboardData" Executed="OnPasteExecuted"/>

And the code for OnPasteExecuted is this:

private void OnPasteExecuted(object sender, ExecutedRoutedEventArgs e)
{
    CurrentView.Paste();
    e.Handled = true;
}

That code gets executed twice, and I have no idea why, we also have the other commands: Cut, Copy, Undo, Redo, those work just fine, the problem is only with Paste. Let me know if you have any idea of what could be going on.

Oh, btw, this only happens when we use the keyboard gesture "Ctrl + V", if we use the command through a button, it doesn't happen. And it's the very same command.

Thanks!

EDIT:

This is how one of the buttons is bound:

<igRibbon:ButtonTool Id="pasteTool" Command="ApplicationCommands.Paste" Caption="Paste" igRibbon:RibbonGroup.MaximumSize="ImageAndTextLarge"
                                SmallImage="Images/Ribbon/Copy16.png" LargeImage="Images/Ribbon/Copy32.png" />

And this is the context menu item:

<UserControl.ContextMenu>
    <ContextMenu Opened="ContextMenu_Opened">
        <MenuItem Command="ApplicationCommands.Paste"/>
    </ContextMenu>
</UserControl.ContextMenu>
A: 

This is more of a comment than a question but I'm a rep-less wonder.

  • Is the call stack the same on both calls?
  • Is sender the same?
  • What sort of gui control is it?
David Hollinshead
The e.OriginalSource was not the same (your answer gave me the idea to check that). One of the controls the command is bound to, registers it twice, I just check the OriginalSource and if it's that control, I don't allow it to do the paste code. Thanks!
Carlo