I have binded the key binding to my wpf main window as below,
<Window.InputBindings>
<KeyBinding Key="F2" Command="{Binding TestCommand}"/>
</Window.InputBindings>
Normally it executes fine. If any new child window is opened(currently focused) means, the main window key binding not works.
I know, key binding will execute for focused item only, But here i want to execute even if it is not focused. Any way to do this and if it is possible please share your idea to me.
This is serious issue to me.
Any one please provide your suggestion?
WPF Behavior: Global Application Shortcut Keys
Seems to be what you're looking for. I made a couple small modifications to the author's code to get your required functionality(rather than passing in an InputBindings collection, made the Behavior pick it from the AssociatedObject directly. Also took out the restriction for requiring modifier keys, Although I suggest you do read through the author's notes in the article and incorporate it to your requirements)
Sample download for your requirements
^^ I could get your required behavior, however do go through the Behavior<T> to see if you can optimise it better for yourself(only bit's I actually looked into was just stuff relating to your specific requirement.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With