I have a UserControl with a number of buttons that run applications on double click. The button command is bound to the UserControl's ViewModel.LaunchApplicationCommand The command is passed a parameter which is the viewmodel of the button.
Here's the button command that works:
<Button.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding ViewModel.LaunchApplicationCommand, ElementName=UserControl}" CommandParameter="{Binding}" />
</Button.InputBindings>
What I'm trying to do is run the same command from a context menu on the button. I've tried to bind it to the best of my limited knowledge, but it doesn't work. What's the right way to do this?
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Run" Command="{Binding ViewModel.LaunchApplicationCommand, ElementName=UserControl}"
CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
</ContextMenu>
</Button.ContextMenu>