/// <summary> /// This is the method that responds to the KeyDown event. /// </summary> /// <param name="e">Event Arguments</param> protected override void OnKeyDown(KeyEventArgs e) { bool handled = true; Key key = e.Key; switch (key) { case Key.Divide: case Key.Oem2: // Ctrl-Fowardslash = Select All if (((Keyboard.Modifiers & ModifierKeys.Control) == (ModifierKeys.Control)) && (SelectionMode == SelectionMode.Extended)) { SelectAll(); } else { handled = false; } break; case Key.Oem5: // Ctrl-Backslash = Select the item with focus. if (((Keyboard.Modifiers & ModifierKeys.Control) == (ModifierKeys.Control)) && (SelectionMode == SelectionMode.Extended)) { ListBoxItem focusedItemUI = (FocusedInfo != null) ? FocusedInfo.Container as ListBoxItem : null; if (focusedItemUI != null) { MakeSingleSelection(focusedItemUI); } } else { handled = false; } break; case Key.Up: case Key.Left: case Key.Down: case Key.Right: { KeyboardNavigation.ShowFocusVisual(); // Depend on logical orientation we decide to move focus or just scroll // shouldScroll also detects if we can scroll more in this direction bool shouldScroll = ScrollHost != null; if (shouldScroll) { shouldScroll = ((key == Key.Down && IsLogicalHorizontal && DoubleUtil.GreaterThan(ScrollHost.ScrollableHeight, ScrollHost.VerticalOffset))) || ((key == Key.Up && IsLogicalHorizontal && DoubleUtil.GreaterThan(ScrollHost.VerticalOffset, 0d))) || ((key == Key.Right && IsLogicalVertical && DoubleUtil.GreaterThan(ScrollHost.ScrollableWidth, ScrollHost.HorizontalOffset))) || ((key == Key.Left && IsLogicalVertical && DoubleUtil.GreaterThan(ScrollHost.HorizontalOffset, 0d))); } if (shouldScroll) { ScrollHost.ScrollInDirection(e); } else { if ((ItemsHost != null && ItemsHost.IsKeyboardFocusWithin) || IsKeyboardFocused) { if (!NavigateByLine(KeyboardNavigation.KeyToTraversalDirection(key), new ItemNavigateArgs(e.Device, Keyboard.Modifiers))) { handled = false; } } else { handled = false; } } } break; case Key.Home: NavigateToStart(new ItemNavigateArgs(e.Device, Keyboard.Modifiers)); break; case Key.End: NavigateToEnd(new ItemNavigateArgs(e.Device, Keyboard.Modifiers)); break; case Key.Space: case Key.Enter: { if (e.Key == Key.Enter && (bool)GetValue(KeyboardNavigation.AcceptsReturnProperty) == false) { handled = false; break; } // If the event came from a ListBoxItem that's a child of ours, then look at it. ListBoxItem source = e.OriginalSource as ListBoxItem; // If ALT is down & Ctrl is up, then we shouldn't handle this. (system menu) if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Alt)) == ModifierKeys.Alt) { handled = false; break; } // If the user hits just "space" while text searching, do not handle the event // Note: Space cannot be the first character in a string sent to ITS. if (IsTextSearchEnabled && Keyboard.Modifiers == ModifierKeys.None) { TextSearch instance = TextSearch.EnsureInstance(this); // If TextSearch enabled and Prefix is not empty // then let this SPACE go so ITS can process it. if (instance != null && (instance.GetCurrentPrefix() != String.Empty)) { handled = false; break; } } if (source != null && ItemsControlFromItemContainer(source) == this) { switch (SelectionMode) { case SelectionMode.Single: if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { MakeToggleSelection(source); } else { MakeSingleSelection(source); } break; case SelectionMode.Multiple: MakeToggleSelection(source); break; case SelectionMode.Extended: if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Control) { // Only CONTROL MakeToggleSelection(source); } else if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Shift) { // Only SHIFT MakeAnchorSelection(source, true /* clearCurrent */); } else if ((Keyboard.Modifiers & ModifierKeys.Shift) == 0) { MakeSingleSelection(source); } else { handled = false; } break; } } else { handled = false; } } break; case Key.PageUp: NavigateByPage(FocusNavigationDirection.Up, new ItemNavigateArgs(e.Device, Keyboard.Modifiers)); break; case Key.PageDown: NavigateByPage(FocusNavigationDirection.Down, new ItemNavigateArgs(e.Device, Keyboard.Modifiers)); break; default: handled = false; break; } if (handled) { e.Handled = true; } else { base.OnKeyDown(e); } }
/// <summary>Responds to the <see cref="E:System.Windows.UIElement.KeyDown" /> event. </summary> /// <param name="e">Provides data for <see cref="T:System.Windows.Input.KeyEventArgs" />.</param> // Token: 0x06005131 RID: 20785 RVA: 0x0016C2F0 File Offset: 0x0016A4F0 protected override void OnKeyDown(KeyEventArgs e) { bool flag = true; Key key = e.Key; if (key <= Key.Down) { if (key != Key.Return) { switch (key) { case Key.Space: break; case Key.Prior: base.NavigateByPage(FocusNavigationDirection.Up, new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers)); goto IL_379; case Key.Next: base.NavigateByPage(FocusNavigationDirection.Down, new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers)); goto IL_379; case Key.End: base.NavigateToEnd(new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers)); goto IL_379; case Key.Home: base.NavigateToStart(new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers)); goto IL_379; case Key.Left: case Key.Up: case Key.Right: case Key.Down: { KeyboardNavigation.ShowFocusVisual(); bool flag2 = base.ScrollHost != null; if (flag2) { flag2 = ((key == Key.Down && base.IsLogicalHorizontal && DoubleUtil.GreaterThan(base.ScrollHost.ScrollableHeight, base.ScrollHost.VerticalOffset)) || (key == Key.Up && base.IsLogicalHorizontal && DoubleUtil.GreaterThan(base.ScrollHost.VerticalOffset, 0.0)) || (key == Key.Right && base.IsLogicalVertical && DoubleUtil.GreaterThan(base.ScrollHost.ScrollableWidth, base.ScrollHost.HorizontalOffset)) || (key == Key.Left && base.IsLogicalVertical && DoubleUtil.GreaterThan(base.ScrollHost.HorizontalOffset, 0.0))); } if (flag2) { base.ScrollHost.ScrollInDirection(e); goto IL_379; } if ((base.ItemsHost == null || !base.ItemsHost.IsKeyboardFocusWithin) && !base.IsKeyboardFocused) { flag = false; goto IL_379; } if (!base.NavigateByLine(KeyboardNavigation.KeyToTraversalDirection(key), new ItemsControl.ItemNavigateArgs(e.Device, Keyboard.Modifiers))) { flag = false; goto IL_379; } goto IL_379; } default: goto IL_377; } } if (e.Key == Key.Return && !(bool)base.GetValue(KeyboardNavigation.AcceptsReturnProperty)) { flag = false; goto IL_379; } ListBoxItem listBoxItem = e.OriginalSource as ListBoxItem; if ((Keyboard.Modifiers & (ModifierKeys.Alt | ModifierKeys.Control)) == ModifierKeys.Alt) { flag = false; goto IL_379; } if (base.IsTextSearchEnabled && Keyboard.Modifiers == ModifierKeys.None) { TextSearch textSearch = TextSearch.EnsureInstance(this); if (textSearch != null && textSearch.GetCurrentPrefix() != string.Empty) { flag = false; goto IL_379; } } if (listBoxItem == null || ItemsControl.ItemsControlFromItemContainer(listBoxItem) != this) { flag = false; goto IL_379; } switch (this.SelectionMode) { case SelectionMode.Single: if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { this.MakeToggleSelection(listBoxItem); goto IL_379; } this.MakeSingleSelection(listBoxItem); goto IL_379; case SelectionMode.Multiple: this.MakeToggleSelection(listBoxItem); goto IL_379; case SelectionMode.Extended: if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Control) { this.MakeToggleSelection(listBoxItem); goto IL_379; } if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == ModifierKeys.Shift) { this.MakeAnchorSelection(listBoxItem, true); goto IL_379; } if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.None) { this.MakeSingleSelection(listBoxItem); goto IL_379; } flag = false; goto IL_379; default: goto IL_379; } } else if (key != Key.Divide && key != Key.Oem2) { if (key == Key.Oem5) { if ((Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control || this.SelectionMode != SelectionMode.Extended) { flag = false; goto IL_379; } ListBoxItem listBoxItem2 = (base.FocusedInfo != null) ? (base.FocusedInfo.Container as ListBoxItem) : null; if (listBoxItem2 != null) { this.MakeSingleSelection(listBoxItem2); goto IL_379; } goto IL_379; } } else { if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && this.SelectionMode == SelectionMode.Extended) { this.SelectAll(); goto IL_379; } flag = false; goto IL_379; } IL_377: flag = false; IL_379: if (flag) { e.Handled = true; return; } base.OnKeyDown(e); }