System.Windows.Interactivity.dllとMicrosoft.Expression.Interaction.dllを使用して、MVVMWPFプロジェクトのViewmodelでイベント処理を行っています。以下は私のXaml内のコードです:
<ItemsControl ItemsSource="{Binding Path= HeaderList}" Grid.Row="0" Grid.Column="0" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}" Width="100" HorizontalAlignment="Left" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<ie:CallMethodAction MethodName="PrevMouseDownEventHandler" TargetObject="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
このために、同じXamlに名前空間を追加しました。
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ie="http://schemas.microsoft.com/expression/2010/interactions"
PrevMouseDownEventHandler
ビューモデルでは、XamlのEventTigger内でCallMethodとして言及したものと同じ名前のメソッドを作成しました。
TextBlockでマウスボタンを押したときにアプリケーションを実行すると、イベントが生成され、メソッドを探し PrevMouseDownEventHandler
て、次の例外が発生します。
Could not find method named 'PrevMouseDownEventHandler' on object of type 'string' that matches the expected signature.
このメソッドは、私のViewModelでは以下のとおりです。
public void PrevMouseMoveEventHandler(object sender, MouseButtonEventArgs e)
{
// Some implementation here;
}
どこが間違っているのかわかりません。これを除いて、Viewmodel内のすべての機能は私にとっては正常に機能しています。これに対する可能な解決策は何でしょうか?