本文介绍了在特定键上使用EventTrigger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在触摸特定键(例如,空格键)时使用EventTrigger调用命令
I would like to invoke a command using EventTrigger when a particular key is touched (for example, the spacebar key)
目前,我有:
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<i:InvokeCommandAction Command="{Binding DoCommand}" CommandParameter="{BindingText}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
现在我如何指定仅当KeyDown与空格键一起出现时才出现这种情况?
Now how can I specify that this should occur only when the KeyDown occurs with the spacebar?
推荐答案
您将必须构建一个自定义触发器来处理该问题:
You would have to build a custom Trigger to handle that:
public class SpaceKeyDownEventTrigger : EventTrigger {
public SpaceKeyDownEventTrigger() : base("KeyDown") {
}
protected override void OnEvent(EventArgs eventArgs) {
var e = eventArgs as KeyEventArgs;
if (e != null && e.Key == Key.Space)
this.InvokeActions(eventArgs);
}
}
这篇关于在特定键上使用EventTrigger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!