WPF System.Windows.Interactivity 使用示例
System.Windows.Interactivity 用于绑定多个事件,类似于多个触发器(MultiTrigger)
在Nuget搜索System.Windows.Interactivity下载安装到项目中
在XAML中引用
引用方式一:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
引用方式二:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
示例一:Button的多个事件(命令)
<Button Name="btn" Content="绑定多个Command"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding Command1}" CommandParameter="1" /> </i:EventTrigger> <i:EventTrigger EventName="MouseMove"> <i:InvokeCommandAction Command="{Binding Command2}" CommandParameter="{Binding ElementName=btn}" /> </i:EventTrigger> </i:Interaction.Triggers> </Button>
参考:https://blog.csdn.net/qinzheng_chen/article/details/104191677