在 WPF 中释放鼠标左键时如何触发事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25435134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I trigger an event when the left mouse button gets released in WPF?
提问by KrisW
I need to trigger an event when the left mouse button gets released. I've tried this:
我需要在释放鼠标左键时触发一个事件。我试过这个:
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseClick" >
<i:InvokeCommandAction Command="{Binding OnBarGroupChangeCommand}" CommandParameter="{Binding ElementName=ReportsBarGroup, Path=Key}" />
</i:EventTrigger>
</i:Interaction.Triggers>
and this
和这个
<igWPF:OutlookBarGroup.InputBindings>
<MouseBinding MouseAction="LeftClick"
Command="{Binding OnBarGroupChangeCommand}" CommandParameter="{Binding ElementName=ReportsBarGroup, Path=Key}"/>
</igWPF:OutlookBarGroup.InputBindings>
These both work. The problem with both cases is that the event fires when the button gets pressed. I need it to fire only when the button gets released. The MouseBinding does not seem to support this. Is there a way to do this with Interaction? What is the best way to handle this? Thanks.
这些都有效。这两种情况的问题在于按下按钮时会触发事件。我需要它只在按钮被释放时触发。MouseBinding 似乎不支持这一点。有没有办法通过交互来做到这一点?处理这个问题的最佳方法是什么?谢谢。
回答by allen1
Try EventTrigger event name "MouseLeftButtonUp".
尝试 EventTrigger 事件名称“ MouseLeftButtonUp”。

