WPF应用程序MVVM中的Hanndling鼠标事件 [英] Hanndling mouse event in WPF application MVVM

查看:280
本文介绍了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?

推荐答案

请参见此处

WPF DrawTools [
see here

WPF DrawTools[^]


这篇关于WPF应用程序MVVM中的Hanndling鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆