(Caliburn Micro)将ActionMessage方法名称映射到ViewModel的子对象 [英] (Caliburn Micro) Mapping a ActionMessage Methodname to a Child Object of the ViewModel
问题描述
我想将caliburn.micro actionmessage的methodname属性绑定到ViewModel的子对象上的方法上。
I would like to bind the methodname propererty of the caliburn.micro actionmessage to a method on a child object of the ViewModel.
我认为它应该如何工作:
How I would imagine it should work:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="MenuItemX.Clicked" />
</i:EventTrigger>
</i:Interaction.Triggers>
这里的问题是方法名不是直接存在于viewmodel上,而是存在于
The problem here is that the methodname does not live directly on the viewmodel, but on a childobject of the viewmodel.
因此在这种情况下,我想绑定到:
ViewModel.MenuItemX.Clicked()
So in this case I would like to bind to: ViewModel.MenuItemX.Clicked()
当前解决方法是在我的viewmodel上有一个传递方法,该方法会闻起来。
Current workaround is having a pass-through method on my viewmodel which smells.
推荐答案
您可以设置实际目标使用 cal:Action.TargetWithoutContext
附加属性的操作(MenuItemX):
You can set the actual target 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>
或更短的语法:
<Button cal:Action.TargetWithoutContext="{Binding MenuItemX}"
cal:Message.Attach="Clicked" />
这篇关于(Caliburn Micro)将ActionMessage方法名称映射到ViewModel的子对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!