protected override void OnPreviewKeyPress(KeyEventArgs e) { base.OnPreviewKeyPress(e); // If list has focus, handle these keys here, to prevent them getting processed by other handlers if (e.Key == Key.Rew && OnHome()) { e.Handled = true; } else if (e.Key == Key.Fwd && OnEnd()) { e.Handled = true; } }
protected override void OnKeyPress(KeyEventArgs e) { // migration from OnKeyPressed(ref Key key) // - no need the check if already handled, b/c this is done by the invoker // - no need to check if any child has focus, since event was originally invoked on focused element, // and the bubbles up the visual tree. This should also handle the subScroller issue, since the // sub scroller is asked 1st if it wants to handle the input // - instead of setting key to None, we set e.Handled = true if (e.Key == Key.Down && OnDown()) { e.Handled = true; } else if (e.Key == Key.Up && OnUp()) { e.Handled = true; } else if (e.Key == Key.Left && OnLeft()) { e.Handled = true; } else if (e.Key == Key.Right && OnRight()) { e.Handled = true; } else if (e.Key == Key.Home && OnHome()) { e.Handled = true; } else if (e.Key == Key.End && OnEnd()) { e.Handled = true; } else if (e.Key == Key.PageDown && OnPageDown()) { e.Handled = true; } else if (e.Key == Key.PageUp && OnPageUp()) { e.Handled = true; } }
protected override void OnKeyPress(KeyEventArgs e) { e.Handled = e.Key == Key.Left && OnLeft() || e.Key == Key.Right && OnRight(); }
/// <summary> /// Invoked when unhandled KeyPress event reaches this element. This method is called before the KeyPress event is fired. /// </summary> /// <param name="e">The event arguments for the event.</param> /// <remarks>This base implementation is empty.</remarks> protected virtual void OnKeyPress(KeyEventArgs e) { }
private static void OnKeyPressThunk(object sender, KeyEventArgs e) { var uiElement = sender as UIElement; if (uiElement != null) { uiElement.OnKeyPress(e); } }
protected override void OnKeyPress(KeyEventArgs e) { // migration from OnKeyPressed(ref Key key) // - no need the check if already handled, b/c this is done by the invoker // - no need to check if any child has focus, since event was originally invoked on focused element, // and the bubbles up the visual tree. This should also handle the subScroller issue, since the // sub scroller is asked 1st if it wants to handle the input // - instead of setting key to None, we set e.Handled = true if (e.Key == Key.Down && OnDown()) e.Handled = true; else if (e.Key == Key.Up && OnUp()) e.Handled = true; else if (e.Key == Key.Left && OnLeft()) e.Handled = true; else if (e.Key == Key.Right && OnRight()) e.Handled = true; else if (e.Key == Key.Home && OnHome()) e.Handled = true; else if (e.Key == Key.End && OnEnd()) e.Handled = true; else if (e.Key == Key.PageDown && OnPageDown()) e.Handled = true; else if (e.Key == Key.PageUp && OnPageUp()) e.Handled = true; }
protected void ExecuteKeyPress(KeyEvent evt) { Key key = evt.Key; if (key == null) { return; } if (KeyPreview != null) { KeyPreview(ref key); } if (key == null) { return; } var routedKeyEventArgs = new KeyEventArgs(Environment.TickCount, key); // invoke routed KeyPress event // if event is already handled, we set Handled to true. By this only handlers registered with handledEventsToo = true will be invoked if (key == Key.None) { routedKeyEventArgs.Handled = true; } ExecuteRoutedInputEvent(new RoutedInputEvent(routedKeyEventArgs, UIElement.PreviewKeyPressEvent)); if (routedKeyEventArgs.Handled) { key = Key.None; } if (key != Key.None) { // Try key bindings... KeyAction keyAction; lock (_syncObj) if (!_keyBindings.TryGetValue(key, out keyAction)) { keyAction = null; } if (keyAction != null) { keyAction.Action(); } } // invoke routed KeyPress event // if event is already handled, we set Handled to true. By this only handlers registered with handledEventsToo = true will be invoked // it is important to invoke routed KeyPressed event before 'internal' OnKeyPressed, // b/c internal OnKeyPress makes focus handling in Screen as final action if event was not handled if (key == Key.None) { routedKeyEventArgs.Handled = true; } ExecuteRoutedInputEvent(new RoutedInputEvent(routedKeyEventArgs, UIElement.KeyPressEvent)); if (routedKeyEventArgs.Handled) { key = Key.None; } if (key != Key.None) { KeyPressedHandler dlgt = KeyPressed; if (dlgt != null) { dlgt(ref key); } } }
protected override void OnKeyPress(KeyEventArgs e) { // migration from OnKeyPressed: // - no need to call base class // - no need to check if focus is in scope, since bubbling event is only raised from inside int updatedStartsWithIndex = -1; try { if (e.Key.IsPrintableKey) { if (e.Key.RawCode.HasValue && (_startsWithIndex == -1 || _startsWith != e.Key.RawCode)) { _startsWith = e.Key.RawCode.Value; updatedStartsWithIndex = 0; } else updatedStartsWithIndex = _startsWithIndex + 1; e.Handled = true; if (!FocusItemWhichStartsWith(_startsWith, updatedStartsWithIndex)) updatedStartsWithIndex = -1; } } finally { // Will reset the startsWith function if no char was pressed _startsWithIndex = updatedStartsWithIndex; } }