(Caliburn Micro) Map an ActionMessage method to a child ViewModel

I would like to bind the methodname property to the caliburn.micro request to the method of the child ViewModel.

As I think it should work:

<i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <cal:ActionMessage MethodName="MenuItemX.Clicked" /> </i:EventTrigger> </i:Interaction.Triggers> 

The problem is that the method name does not live directly on the viewmodel, but on the child of the viewmodel.

So, in this case, I would like to bind to: ViewModel.MenuItemX.Clicked ()

The current workaround has a pass-through method on my view model that smells.

+4
source share
1 answer

You can set the real purpose of the action (MenuItemX) using cal:Action.TargetWithoutContext attached property:

 <Button cal:Action.TargetWithoutContext="{Binding MenuItemX}" > <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <cal:ActionMessage MethodName="Clicked" /> </i:EventTrigger> </i:Interaction.Triggers> </Button> 

or shorter syntax:

 <Button cal:Action.TargetWithoutContext="{Binding MenuItemX}" cal:Message.Attach="Clicked" /> 
+7
source

All Articles