In the MainView of my code, I had this event to catch keyDown:
#region Constructor PreviewKeyDown += SoftKeyMainPreviewKeyDown; #endregion private void SoftKeyMainPreviewKeyDown(object sender, KeyEventArgs e) { var focusedElement = Keyboard.FocusedElement; switch (e.Key) { case Key.Up: DoSomething(); break; ..... } }
Now I want to move this to InputBindings in XAML.
My first attempt:
<UserControl.InputBindings> <KeyBinding Gesture="Up" Command="{Binding ElementName=_MaschinenView, Path=UpCommand}" /> .... </UserControl.InputBindings>
CodeBehind:
public ICommand UpCommand { get; set; } UpCommand = new SimpleCommand { ExecuteDelegate = delegate { MoveFocusInDirection(Keyboard.FocusedElement, new TraversalRequest(FocusNavigationDirection.Up)); } };
Nothing happens to this. Most likely, a KeyDown-Event is handled by a child.
Is it possible to set preview in XAML in InputBindings? And how can this be achieved?
source share