The copy test command Copy (in Button) is connected via Command with ApplicationCommands.Copy

How to invoke the command Command = "Copy" from ContextMenu Click?

Click Attempts to find a command in Window1 and not in ApplicationCommands.Copy.

Severity Code Description Project File String Suppression State Error CS1061 'Window1 "does not contain a definition for" Copy "and could not find the" Copy "extension method that accepts the type" Window1 "as the first argument (possibly using a directive or a link to the assembly) . \ Window1.xaml 1365 Active

<Button Command="Copy"> <Button.ToolTip> <ToolTip > <StackPanel> <TextBlock /> </StackPanel> </ToolTip> </Button.ToolTip> </Button> 
 CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopy, CanCutOrCopy)); TextAreaDefaultInputHandler.WorkaroundWPFMemoryLeak(InputBindings); 
 <ContextMenu> <MenuItem Click="Copy"> </MenuItem> </ContextMenu> 

    2 answers 2

    Resolved by replacing Click with Command

     <MenuItem Command="Copy" > 

      How to solve, you have already written, and I will add why this happens.

      The conversion of the text "Copy" into ApplicationCommands.Copy done with the help of a type converter. Type converter in the command is really looking for among ApplicationCommands.* . But the Click type is not a command, but an event, so the rules for teams do not apply here.