【问题标题】:How t add Gesture inside XAML from code behind如何从后面的代码在 XAML 中添加手势
【发布时间】:2019-10-06 08:25:52
【问题描述】:

所以我有这个KeyBinding:

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

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

Gesture="Ctrl+Alt+S"

有什么建议吗?

【问题讨论】:

标签: wpf xaml key-bindings


【解决方案1】:

创建一个KeyGesture。 ModifierKeys 是一个标志enum:

KeyBinding binding = new KeyBinding()
{ 
    Gesture = new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Alt) 
};

【讨论】:

  • 以及如何将其添加到我的应用程序中?这个键会在后台工作吗?
  • @falukky:您将在窗口的this.InputBindings 中添加一个KeyBinding。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 2011-03-02
  • 1970-01-01
相关资源
最近更新 更多