1
는 나는이 같은 숫자 키패드 키에 바인딩 명령이있는 창이 있습니다WPF 무시/자식 컨트롤에 키 바인딩을 다시
ICommand _onReasonShortcutKeyPressedCommand;
public ICommand OnReasonShortcutKeyPressedCommand
{
get
{
return _onReasonShortcutKeyPressedCommand ??
(_onReasonShortcutKeyPressedCommand = new RelayCommand(OnReasonShortcutKeyPressedCommand_Execute));
}
}
private void OnReasonShortcutKeyPressedCommand_Execute(object param)
{
//Find which key was presses by command param
int keyPressed = Int32.Parse((string)param);
// Do something bla bla bla
}
: 백엔드에서
<!-- Set keybindings -->
<controls:MetroWindow.InputBindings>
<!-- NumPad Shortcuts for selecting reasons -->
<KeyBinding Key="NumPad0" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="0" />
<KeyBinding Key="NumPad1" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="1" />
<KeyBinding Key="NumPad2" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="2" />
<KeyBinding Key="NumPad3" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="3" />
<KeyBinding Key="NumPad4" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="4" />
<KeyBinding Key="NumPad5" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="5" />
<KeyBinding Key="NumPad6" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="6" />
<KeyBinding Key="NumPad7" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="7" />
<KeyBinding Key="NumPad8" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="8" />
<KeyBinding Key="NumPad9" Command="{Binding OnReasonShortcutKeyPressedCommand}" CommandParameter="9" />
<!-- Others -->
<KeyBinding Key="Back" Command="{Binding OnReasonGoBackClickedCommand}" />
<KeyBinding Key="Escape" Command="{Binding OnEscapeClickedCommand}" />
</controls:MetroWindow.InputBindings>
을이 같이 처리됩니다
이제이 창에는 숫자를 입력해야하는 텍스트 상자가 포함됩니다. 물론 창 수준의 키 바인딩을 사용하면 실제 번호가 인쇄되는 대신 명령이 트리거됩니다. 이걸 무시할 수 있습니까?