2013-04-08 67 views
1

我實現WPF MVVM嚮導,我想知道一個新的嚮導的頁面(用戶控件)被加載時執行DoOperation的正確方法。WPF MVVM嚮導

MyWizard.ViewModal類上實現,而UserControl負載在MyWizard.View名稱空間上發生。

如何連接UserControl加載事件到DoOperation api?

我試過如下:

<xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 

<i:Interaction.Triggers> 

    <i:EventTrigger EventName="Loaded"> 
     <i:InvokeCommandAction Command="{Binding Path=RunOperation}"/ 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

RunOperation電話DoOperation

它不起作用,RunOperation沒有被調用。

這是正確的做法或有在MyWizard.ViewModal類來執行操作的更好的辦法?

回答

0

您的方法應該可行。你有沒有檢查你的輸出控制檯的綁定錯誤?是RunOperation一個命令?當提升Loaded事件時,是否已設置UserControl的DataContext?您是否在UC中實施了這種觸發器?

<UserControl x:Class="..." 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     
      xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"> 

    <i:Interaction.Triggers> 

     <i:EventTrigger EventName="Loaded"> 
      <i:InvokeCommandAction Command="{Binding Path=RunOperation}"/> 
     </i:EventTrigger> 

    </i:Interaction.Triggers> 

    <Grid> 
     ... 
    </Grid> 

</UserControl>