两个步骤:1、添加以下两个程序集System.Windows.InteractivityMicrosoft.Expression.Interactions 2、添加xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
<CheckBox > <CheckBox.DataContext> <vm:StudentListViewModel></vm:StudentListViewModel> </CheckBox.DataContext> <i:Interaction.Triggers> <i:EventTrigger EventName="Checked"> <ei:CallMethodAction TargetObject="{Binding }" MethodName="Select"> </ei:CallMethodAction> </i:EventTrigger> <i:EventTrigger EventName="Unchecked"> <ei:CallMethodAction TargetObject="{Binding }" MethodName="UnSelect"></ei:CallMethodAction> </i:EventTrigger> </i:Interaction.Triggers> </CheckBox>
<Button Content="View" Name="button1" Width="150" IsEnabled="{Binding CanSubmit}"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <ei:CallMethodAction TargetObject="{Binding}" MethodName="Submit"></ei:CallMethodAction> </i:EventTrigger> </i:Interaction.Triggers> </Button> //CallMethodAction 操作来调用为指定对象定义的方法。所调用的方法必须是不采用参数并且不返回值的公共方法,或是其签名与事件处理程序的签名相匹配的公共方法。