我有一個很奇怪的問題。在我的WP7應用程序中,我有一個透視控件和一個定義在其中的項目模板(或者在資源中,我已經嘗試了兩種方式,但仍然是相同的問題)。在模板中,我定義了一個EventToCommand定義的按鈕(EventName =「Click」)。我也在Pivot外面有相同的複製粘貼按鈕。問題是,按鈕,這是在樞軸以外的工作正常,但其中一個不起作用。其實我已經注意到,我的樞軸內的任何命令不起作用。我正確處理ViewModel中的命令,因爲同一個按鈕,但在數據透視之外效果很好。 任何想法可能是什麼問題?請幫助。 在此先感謝。 乾杯。MVVM Light EventToCommand在WP7 Pivot DataTemplate中不起作用
P.S.我的代碼是非常標準的,但萬一這裏是:
<controls:Pivot Grid.Row="0"
x:Name="PivotControl"
Title="{Binding ApplicationTitle}"
ItemsSource="{Binding BlaBla}">
<controls:Pivot.ItemTemplate>
<DataTemplate>
<StackPanel>
<Button Content="Click Me">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding MyCommand, Mode=OneWay}" CommandParameterValue="Test"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
...
而且視圖模型代碼:
public RelayCommand<string> MyCommand
{
get;
private set;
}
//And in the constructor ...
MyCommand= new RelayCommand<string>((param) => HandleTheCommand(param));
...
比ks再次。
謝謝史蒂芬,真的很好的答案。乾杯。 – Tech0 2010-10-29 18:06:32