Keyboard events in a WPF MVVM application?

前端 未结 8 1941
情深已故
情深已故 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:00

    I looked into that issue a few months ago, and I wrote a markup extension that does the trick. It can be used like a regular binding :

    
        
    
    

    The full source code for this extension can be found here :

    http://www.thomaslevesque.com/2009/03/17/wpf-using-inputbindings-with-the-mvvm-pattern/

    Please be aware that this workaround is probably not very "clean", because it uses some private classes and fields through reflection...

提交回复
热议问题