gpt4 book ai didi

wpf - 在 WPF 中使用多个修饰键创建 KeyBinding

转载 作者:行者123 更新时间:2023-12-02 05:35:41 28 4
gpt4 key购买 nike

我创建KeyBinding的方式是这样的:

<KeyBinding Modifiers="Ctrl" Key="S" Command="{Binding SaveCommand}" />

但是如果我需要两个修饰键怎么办?例如,Ctrl + Shift

最佳答案

文档指出您可以使用 + 字符分隔修饰符:

<KeyBinding Modifiers="Ctrl+Shift" Key="S" Command="{Binding SaveCommand}" />

参见here对于血淋淋的细节,下面提取了相关部分,以防链接消失:

<小时/>

XAML

<object property="oneOrMoreModifierKeys"/>

XAML 值

oneOrMoreModifierKeys — 一个或多个修饰键,由 ModifierKeys 枚举定义,以 + 字符分隔。

<小时/>

您还可以单独使用手势,而不是使用按键/修饰符组合:

<KeyBinding Gesture="Ctrl+Shift+S" Command="{Binding SaveCommand}" />

根据相同的文档链接:

When defining a KeyBinding in XAML, there are two ways to specify the KeyGesture.

The first way to establish a KeyBinding in XAML is to define the Gesture attribute of the KeyBinding element, which enables a syntax to specify keys and modifiers as a single string, for example "CTRL+P".

The second way is to define the Key attribute and the Modifiers attributes of the KeyBinding element.

Both ways of setting the KeyGesture are equivalent and modify the same underlying object, but there will be a conflict if both are used. In the case when the Key, Modifiers, and the Gesture attributes are all set, the attribute which is defined last will be used for the KeyGesture.

关于wpf - 在 WPF 中使用多个修饰键创建 KeyBinding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4050066/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com