I'm using C#, WPF, ReactiveUI and Prism to create an application with many different views (user controls). On some views there are buttons/menu items that bind to a command in the view model. I would like these buttons to also activate using a key combination such as ctrl+s, etc....
What I've tried
InputBindings
but that only works when the view that defines these input bindings has focus.ApplicationCommands
the predefined commands likeApplicationCommands.Close
seem useful. I can reference them both in the view and the view model, but I don't know how subscribe to them in my view model. It also seems that I have to 'activate' the command first, or at least change CanExecute since any button bound to such command stays disabled.
What I wish for
Let's say I have a view that represents the top menu bar MenuView
with a button myButton
and a corresponding view model MenuViewModel
with a command myCommand
. I would like to bind myButton
to myCommand
and the keyboard shortcut ctrl+u
to myCommand
without MenuView
knowing about the implementation of its view model. The keyboard shortcut should work as long as the window that contains MenuView
has focus.
I don't really care if the keyboard short-cut is either in the view or view model.