我已經成功地轉換的事件的方法(用於視圖模型使用)使用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事件觸發如上(或使用替代方法),我非常想知道。