private void ThisControl_GotFocus(object sender, RoutedEventArgs e) { if (!Options.IsKeyboardFocusWithin && !TargetLocationSearchTextBox.IsKeyboardFocusWithin && !Flyout.IsKeyboardFocusWithin) { TargetLocationSearchTextBox.Focus(); } }
protected override void OnPreviewKeyDown(KeyEventArgs e) { if (e.Key == Key.Escape && Flyout.IsOpen) { TargetLocationSearchTextBox.Focus(); } }
private void HandleListBoxKeyPress(object sender, KeyEventArgs e) { int index = TargetLocationSearchTextBox.CaretIndex; switch (e.Key) { case Key.Tab: case Key.Enter: CommitSelectionAndMoveFocus(); e.Handled = true; break; case Key.Up: if (Options.SelectedIndex == 0) { SelectedItem = Items[0]; LostFocus -= OnLostFocus; TargetLocationSearchTextBox.Focus(); TargetLocationSearchTextBox.CaretIndex = index; LostFocus += OnLostFocus; } break; case Key.Escape: Flyout.IsOpen = false; TargetLocationSearchTextBox.ScrollToEnd(); e.Handled = true; break; case Key.Down: case Key.PageDown: case Key.PageUp: case Key.Home: case Key.End: break; default: LostFocus -= OnLostFocus; TargetLocationSearchTextBox.Focus(); TargetLocationSearchTextBox.CaretIndex = index; LostFocus += OnLostFocus; break; } }
private void HandleListBoxKeyPress(object sender, KeyEventArgs e) { int index = TargetLocationSearchTextBox.CaretIndex; switch (e.Key) { case Key.Tab: case Key.Enter: Commit(SelectedItem); e.Handled = true; TargetLocationSearchTextBox.Focus(); break; case Key.Up: if (Options.SelectedIndex == 0) { SelectedItem = Items[0]; LostFocus -= OnLostFocus; TargetLocationSearchTextBox.Focus(); TargetLocationSearchTextBox.CaretIndex = index; LostFocus += OnLostFocus; } break; case Key.Escape: e.Handled = true; TargetLocationSearchTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); break; case Key.Down: case Key.PageDown: case Key.PageUp: case Key.Home: case Key.End: break; default: LostFocus -= OnLostFocus; TargetLocationSearchTextBox.Focus(); TargetLocationSearchTextBox.CaretIndex = index; LostFocus += OnLostFocus; break; } }
protected override void OnAccessKey(AccessKeyEventArgs e) { TargetLocationSearchTextBox.Focus(); }
private void CommitSelectionAndMoveFocus() { Commit(SelectedItem); TargetLocationSearchTextBox.Focus(); }