I’ve created solution to reproduce a problem that I’m having with MVVM-Light EventToCommand vs InputBindings. The issue revolves around one window opening another and if I have an InputBinding connected say to the escape key and close the second view, it closes the second view and returns to the first. If I use instead the EventToCommand and then manually call the same command it closed the second view, it also closes the first.
I expect it is a little hard to see without code so I’ve create a test solution to reproduce the problem.
The Steps are as follows:
Works as expected
1) Click the button the first window to open the second.
2) Press the escape key on the second to use the input bindings
Problem Case
1) Click the button the first window to open the second.
2) Click the “Hello” text box
3) Press the Escape key to use the EventToCommand path and both windows close?
You have to notify the WPF eventhandling mechanism that the button press was handled in your event handler and that it should not be bubbled up the event chain. If you don’t your text box is calling close on the active window (window2) and the escape handler is calling close on the active window (window1 as window2 was already closed by the escape handler of the text box). So if you modify your Close2 function as follows everything works fine: