MVVM Light中EventToCommand的使用

来源:互联网 发布:mac强制关机 编辑:程序博客网 时间:2024/05/01 23:04

很多文章在介绍MVVM中Command的使用,其实使用EventToCommand的场景也不少,我使用的是MVVM Light V5.2.0,记录下。

首先,需要在xaml中声明namespace:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
我们以一个button的MouseEnter事件举例:

<Button>    <i:Interaction.Triggers>        <i:EventTrigger EventName="MouseEnter" >             <cmd:EventToCommand Command="{Binding FooCommand}" CommandParameter=""/>        </i:EventTrigger>    </i:Interaction.Triggers></Button>

然后在ViewModel中按照Command的使用来处理MouseEnter事件了。

0 0
原创粉丝点击