I have a UserControl (MainView) that has a viewbox on it to display another UserControl (MidView) and inside that UserControl I have a canvas that shows another UserControl (BottomView). On the grandchild UserControl (BottomView) I have a ListBox that I want to be able to rightclick and call a particular method.
I have
cal:Message.Attach="[Event MouseRightButtonDown] = [Action Method1]"
on the ListBox but whenever I rightclick the box it checks the grandparents ViewModel (MainViewModel) for "Method1". I think I have to use cal:Action.TargetWithoutContext to get it to look in the BottomViewModel but I can't work out how to use it.
I thought
cal:Action.TargetWithoutContext="{Binding MainView}"
or
cal:Action.TargetWithoutContext="{Binding MainViewModel}"
would solve my problem but no luck. Any ideas where I am going wrong?
I've found an old App where I did this for a right click Context menu on a TreeView and needed to execute a method on the actual selected item ViewModel, rather than the parent ViewModel.
I used:
<ContextMenu cal:Action.TargetWithoutContext="{Binding DataContext, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Edit" cal:Message.Attach="Edit" />
<!-- Other Menu Items -->
</ContextMenu>
Hopefully similar logic will apply to your situation (using your desired event/method).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With