Use EventTrigger on a specific key

后端 未结 3 1036
无人共我
无人共我 2021-02-07 14:05

I would like to invoke a command using EventTrigger when a particular key is touched (for example, the spacebar key)

Currently I have:

  

        
3条回答
  •  迷失自我
    2021-02-07 14:46

    Another approach would be to use KeyBindings and bind them to your Window, UserControl, FrameworkElement, etc. That will not Trigger a button, but say you have a command "MyCommand" that is called from the button, you could invoke the command from InputBindings.

    
       
       
    
    
     
        
     
    

    You could also bind these KeyBindings to a TextBox.

提交回复
热议问题