如何从后面的代码中在XAML中添加手势

问题描述 投票:0回答:1

所以我有这个KeyBinding

<Window.InputBindings>
    <KeyBinding Gesture="Ctrl+Alt+S" Command="{Binding TestCommand}"
                HotkeyManager.RegisterGlobalHotkey="True" />
</Window.InputBindings>

而且我的应用程序有几个ToggeButtons,用户需要指定快捷方式ans,我希望能够从后面的代码中更改此快捷方式:

Gesture="Ctrl+Alt+S"

有什么建议吗?

wpf xaml key-bindings
1个回答
0
投票

创建KeyGestureModifierKeys是标志enum

KeyBinding binding = new KeyBinding()
{ 
    Gesture = new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Alt) 
};
© www.soinside.com 2019 - 2024. All rights reserved.