WPF Image控件实现鼠标事件
1.引用
在xaml中引用
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
如果引用失败的话 可能是没有引用相关库System.Windows.Interactivity.dll
2.添加对应事件command
<Image Source="{Binding ImageModel.OpenPath,Converter={StaticResource StrToImageSource}}" Width="30" Height="30" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown" >
<i:InvokeCommandAction Command="{Binding ImageModel.OpenCmd}" CommandParameter="{Binding ElementName=trendUc}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>