WPF项目中,从Nuget搜索并下载System.Windows.Interactivity.dll,安装到项目中,并在XAML界面引入。
<UserControl xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"> .... UserControl>
在目标UI控件上添加一个鼠标右键点击弹起事件。
<i:Interaction.Triggers> <i:EventTrigger EventName="MouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.MouseRightButtonDownCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type Button}}}"/> i:EventTrigger> i:Interaction.Triggers>
现在的问题是:在Visual Studio中书写EventTrigger的EventName时,没有智能提示的,如何查看这里还能写哪些可选的事件?
可选的事件有以下这些:
- https://msdn.microsoft.com/en-us/library/system.windows.controls.grid_events(v=vs.110).aspx
重要的参考:
https://stackoverflow.com/questions/22060381/is-there-a-list-available-for-eventtrigger-eventnames