WPF键盘修改器 [英] WPF Keyboard Modifier on MouseBinding

查看:317
本文介绍了WPF键盘修改器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF中的MVVM模式(两者都有点新)。

I'm working with the MVVM pattern in WPF (a bit new to both).

我想设置一个事件,对应于 Control + Click 事件的复选框上的InputBinding MouseBinding 元素上的修饰符属性。这是我想实现的(虚构的代码,显然 - 修饰符不存在):

I'd like to set up an InputBinding on a CheckBox that corresponds to a Control + Click event, but do not see a Modifiers property on the MouseBinding element. This is what I'd like to achieve (fictitious code, obviously- Modifiers doesn't exist):

<CheckBox>
     <CheckBox.InputBindings>
           <MouseBinding MouseAction="LeftClick" 
                         Command="{Binding CheckboxControlClickCommand}"
                         Modifiers="Control" />
     </CheckBox.InputBindings>
</CheckBox>

有关如何在不使用事件的情况下完成此操作的任何想法?

Any ideas on how to accomplish this without using events?

谢谢!

推荐答案

我最终在ICommand的Execute()上下文中使用Keyboard.Modifiers似乎工作很好。

I ended up using Keyboard.Modifiers in the Execute() context of the ICommand, which seemed to work just fine.

if (Keyboard.Modifiers != ModifierKeys.Control) return;
    ...

这篇关于WPF键盘修改器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆