Creating KeyBinding in WPF with more than one modifier key

前端 未结 5 1454
南旧
南旧 2020-12-08 17:51

The way I created KeyBinding was something like:


         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 18:38

    The documentation states that you can just separate the modifiers with the + character:

    
    

    See here for the gory details, with the relevant bits extracted below in case the link ever disappears:


    XAML

    
    
    

    XAML Values

    oneOrMoreModifierKeys — One or more modifier keys, defined by the ModifierKeys enumeration, delimited with a + character.


    You can also use a gesture on its own rather than a key/modifier combo:

    
    

    as per that same documentation link:

    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.

    提交回复
    热议问题