我已经成功地转换的事件的方法(用于视图模型使用)使用EventTriggerBehavior如下面的示例所示和CallMethodAction(这里挑选用于说明一个页加载事件)。事件到视图模型方法VisualStateGroup
<i:Interaction.Behaviors> <core:EventTriggerBehavior EventName="Loaded"> <core:CallMethodAction TargetObject="{Binding Mode=OneWay}" MethodName="PageLoadedCommand"/> </core:EventTriggerBehavior> </i:Interaction.Behaviors>
然而,没有成功,当涉及到CurrentStateChanged事件的VisualStateGroup如下所示(是的,嵌套在<VisualStateGroup>
块内作为CurrentStateChanged事件属于VisualStateGroup):
<i:Interaction.Behaviors> <core:EventTriggerBehavior EventName="CurrentStateChanged"> <core:CallMethodAction MethodName="CurrentVisualStateChanged" TargetObject="{Binding Mode=OneWay}"/> </core:EventTriggerBehavior> </i:Interaction.Behaviors>
我怀疑VisualStateGroup(或VisualStateManager)和事件可能存在问题。我这样说是因为我可以用这种方法来处理其他事件。我已经检查并重新检查了方法签名(事件参数传递格式),但没有机会。
如果您设法得到CurrentStateChanged事件触发如上(或使用替代方法),我非常想知道。