Analogue ProcessCmdKey in WPF

I am new to WPF and WinForms to add hotkeys to the form that I usually used ProcessCmdKey , which made it easy to redefine (add) key functions (similar to the one described below). Is there an easy way to assign hotkeys in WPF? I use commands with keys, but sometimes it doesnโ€™t work (I think that some other controls in the window respond to these gestures and perform their tasks, so my command cannot respond to a predefined key gesture).

+2
wpf keyboard-shortcuts hotkeys
source share
1 answer

InputBindings have the control area to which they are assigned, if you assigned KeyBinding to Window.InputBindings , they will be triggered throughout the window if the same gesture is not locally redefined if it is defined somewhere down the tree.

For example:

 <UserControl.InputBindings> <KeyBinding Gesture="CTRL+SHIFT+N" Command="{Binding BtnNewChild_Command}" CommandParameter="{Binding ElementName=view}" /> </UserControl.InputBindings> 

does not work, it cannot pass a view element as a parameter, since this UserControl has a control named "view". Does wpf have some โ€œcommonโ€ hotkey assignment scenario?

The problem here will be just a scope, child controls have access to things declared above in the tree, but not vice versa. You could reorganize this to create your view as a resource in UserControl.Resources , then you can refer to it both in CommandParameter and if you use it in UserControl .

+5
source share

Source: https://habr.com/ru/post/649813/


All Articles