protected override void OnPreviewKeyDown(KeyEventArgs args) { base.OnKeyDown(args); args.Handled = true; if (gestCut.Matches(null, args)) { CutOnClick(this, args); } else if (gestCopy.Matches(null, args)) { CopyOnClick(this, args); } else if (gestPaste.Matches(null, args)) { PasteOnClick(this, args); } else if (gestDelete.Matches(null, args)) { DeleteOnClick(this, args); } else { args.Handled = false; } }
protected override SelectionMode HandleKeyboardEvent(object sender, KeyEventArgs keyEventArgs) { if (keyEventArgs.IsDown) { if (SelectionModeManager.IsMultiSelectionKey(keyEventArgs.Key)) { return(this); } if (ToggleSelectionKey.Matches(sender, keyEventArgs)) { log.Debug("Toggling current item's selection"); ToggleItemSelection(); keyEventArgs.Handled = true; } } else if (keyEventArgs.IsUp) { UpdateKeyboardStatus(); if (!ctrlIsDown && !shiftIsDown) { return(SelectionModeManager.SingleSelectionMode); } } return(this); }
// <SnippetKeyDownHandlerKeyGestureMatches> private void OnKeyDown(object sender, KeyEventArgs e) { KeyGesture keyGesture = new KeyGesture(Key.B, ModifierKeys.Control); if (keyGesture.Matches(null, e)) { MessageBox.Show("Trapped Key Gesture"); } }
public void Key_Gesture_Matches_NumPad_To_Regular_Digit(Key gestureKey, Key pressedKey) { var keyGesture = new KeyGesture(gestureKey); Assert.True(keyGesture.Matches(new KeyEventArgs { Key = pressedKey })); }
protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e) { base.OnPreviewKeyDown(e); e.Handled = true; if (exitGesture.Matches(null, e)) { exitMenuItem_Click(this, e); } else { e.Handled = false; } }
public static void RaiseMenuItemClickOnKeyGesture(this ItemsControl control, KeyEventArgs args, bool throwOnError) { if (args == null) { throw new ArgumentNullException("e"); } if (control == null) { return; } KeyGestureConverter kgc = new KeyGestureConverter(); foreach (var item in control.Items.OfType <MenuItem>()) { if (!string.IsNullOrWhiteSpace(item.InputGestureText)) { KeyGesture gesture = null; if (throwOnError) { gesture = kgc.ConvertFrom(item.InputGestureText) as KeyGesture; } else { try { gesture = kgc.ConvertFrom(item.InputGestureText) as KeyGesture; } catch { } } if (gesture != null && gesture.Matches(null, args)) { //System.Diagnostics.Trace.WriteLine("MATCH item:" + item + ", key:" + e.Key + " Keyboard.Modifiers:" + Keyboard.Modifiers); item.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent)); args.Handled = true; return; } } RaiseMenuItemClickOnKeyGesture(item, args, throwOnError); if (args.Handled) { return; } } }
public static void RaiseMenuItemClickOnKeyGesture(this ItemsControl control, KeyEventArgs args, bool throwOnError) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (control == null) { return; } var kgc = new KeyGestureConverter(); foreach (var item in control.Items.OfType <MenuItem>()) { if (!string.IsNullOrWhiteSpace(item.InputGestureText)) { KeyGesture gesture = null; if (throwOnError) { gesture = kgc.ConvertFrom(item.InputGestureText) as KeyGesture; } else { try { gesture = kgc.ConvertFrom(item.InputGestureText) as KeyGesture; } catch { } } if (gesture != null && gesture.Matches(null, args)) { item.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent)); args.Handled = true; return; } } RaiseMenuItemClickOnKeyGesture(item, args, throwOnError); if (args.Handled) { return; } } }
public static IDisposable Attach(TopLevel control, KeyGesture gesture) { void PreviewKeyDown(object sender, KeyEventArgs e) { if (gesture.Matches(e)) { OpenDevTools(control); } } return(control.AddHandler( KeyDownEvent, PreviewKeyDown, RoutingStrategies.Tunnel)); }
public static IDisposable Attach(TopLevel root, KeyGesture gesture) { void PreviewKeyDown(object sender, KeyEventArgs e) { if (gesture.Matches(e)) { Open(root); } } return(root.AddDisposableHandler( InputElement.KeyDownEvent, PreviewKeyDown, RoutingStrategies.Tunnel)); }
public override bool Matches(object targetElement, InputEventArgs inputEventArgs) { var keyEvent = inputEventArgs as KeyEventArgs; if (keyEvent == null) { return(false); } if (_keyGesture != null) { return(_keyGesture.Matches(targetElement, inputEventArgs)); } return(_key == keyEvent.Key); }