WPF应用程序MVVM中的Hanndling鼠标事件
我正在使用System.Windows.Interactivity.dll和Microsoft.Expression.Interaction.dll在MVVM WPF项目的Viewmodel中进行事件处理.以下是我的Xaml中的代码:
I am using System.Windows.Interactivity.dll and Microsoft.Expression.Interaction.dll to do event handling in Viewmodel in my MVVM WPF project. below is the code inside my 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中添加了名称空间.
for this I added namespaces in the same 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方法,并使我陷入以下异常:
在与预期签名匹配的字符串"类型的对象上找不到名为"PrevMouseDownEventHandler"的方法.
此方法如下在我的ViewModel中.
and in my viewmodel I have created a method having PrevMouseDownEventHandler name which is same as that of I mentioned as CallMethod inside EventTigger in the Xaml.
On running my application when I presses mouse button on TextBlock event is generated and look for PrevMouseDownEventHandler method and leave me into following exception:
Could not find method named ''PrevMouseDownEventHandler'' on object of type ''string'' that matches the expected signature.
this method is as below in my ViewModel.
public void PrevMouseMoveEventHandler(object sender, MouseButtonEventArgs e)
{
// Some implementation here;
}
我不知道我要去哪里错了.除此之外,Viewmodel中的所有功能对我来说都很好用.
I don''t have any idea where I am going wrong. Except this all the funtionalities inside Viewmodel is working fine for me. what would be possible solution for this?