Keyboard events in a WPF MVVM application?

前端 未结 8 1948
情深已故
情深已故 2020-11-27 11:30

How can I handle the Keyboard.KeyDown event without using code-behind? We are trying to use the MVVM pattern and avoid writing an event handler in code-behind file.

8条回答
  •  悲哀的现实
    2020-11-27 12:03

    To bring an updated answer, the .net 4.0 framework enables you to do this nicely by letting you bind a KeyBinding Command to a command in a viewmodel.

    So... If you wanted to listen for the Enter key, you'd do something like this:

    
        
            
        
    
    

提交回复
热议问题