Exemple #1
0
 private void ThisControl_GotFocus(object sender, RoutedEventArgs e)
 {
     if (!Options.IsKeyboardFocusWithin && !TargetLocationSearchTextBox.IsKeyboardFocusWithin && !Flyout.IsKeyboardFocusWithin)
     {
         TargetLocationSearchTextBox.Focus();
     }
 }
Exemple #2
0
        private void HandleKeyPress(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Tab:
            case Key.Enter:
                Commit(SelectedItem);
                break;

            case Key.Escape:
                e.Handled = true;
                TargetLocationSearchTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                break;

            case Key.Down:
                if (Options.Items.Count > 0)
                {
                    Options.ScrollIntoView(Options.Items[0]);
                    FrameworkElement fe = (FrameworkElement)Options.ItemContainerGenerator.ContainerFromIndex(0);
                    fe?.Focus();
                    Options.SelectedIndex = 0;
                    e.Handled             = true;
                }
                break;
            }
        }
Exemple #3
0
 protected override void OnPreviewKeyDown(KeyEventArgs e)
 {
     if (e.Key == Key.Escape && Flyout.IsOpen)
     {
         TargetLocationSearchTextBox.Focus();
     }
 }
Exemple #4
0
        private void HandleKeyPress(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Tab:
                if (SelectedItem != null)
                {
                    CommitSelectionAndMoveFocus();
                }
                break;

            case Key.Enter:
                CommitSelectionAndMoveFocus();
                e.Handled = true;
                break;

            case Key.Escape:
                Flyout.IsOpen = false;
                TargetLocationSearchTextBox.ScrollToEnd();
                e.Handled = true;
                break;

            case Key.Down:
                if (Options.Items.Count > 0)
                {
                    Options.ScrollIntoView(Options.Items[0]);
                    FrameworkElement fe = (FrameworkElement)Options.ItemContainerGenerator.ContainerFromIndex(0);
                    fe?.Focus();
                    Options.SelectedIndex = 0;
                    e.Handled             = true;
                }
                break;
            }
        }
Exemple #5
0
        private void PositionCompletions(int index)
        {
            Rect r = TargetLocationSearchTextBox.GetRectFromCharacterIndex(index);

            Flyout.HorizontalOffset = r.Left - 7;
            Options.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Flyout.Width = Options.DesiredSize.Width;
        }
Exemple #6
0
 private void OnLostFocus(object sender, RoutedEventArgs e)
 {
     if (SelectedItem != null && !Options.IsKeyboardFocusWithin)
     {
         Commit(SelectedItem);
         TargetLocationSearchTextBox.ScrollToEnd();
     }
 }
Exemple #7
0
        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;
            }
        }
Exemple #8
0
        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;
            }
        }
Exemple #9
0
        private void HandleKeyPress(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Tab:
                // SelectedItem could be null if the key press came from keyboard navigation and not commit operation.
                // In this case we will just move the focus to next control.
                if (SelectedItem == null)
                {
                    TargetLocationSearchTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                }
                else
                {
                    CommitSelectionAndMoveFocus();
                }

                e.Handled = true;
                break;

            case Key.Enter:
                CommitSelectionAndMoveFocus();
                e.Handled = true;
                break;

            case Key.Escape:
                Flyout.IsOpen = false;
                TargetLocationSearchTextBox.ScrollToEnd();
                e.Handled = true;
                break;

            case Key.Down:
                if (Options.Items.Count > 0)
                {
                    Options.ScrollIntoView(Options.Items[0]);
                    FrameworkElement fe = (FrameworkElement)Options.ItemContainerGenerator.ContainerFromIndex(0);
                    fe?.Focus();
                    Options.SelectedIndex = 0;
                    e.Handled             = true;
                }
                break;
            }
        }
Exemple #10
0
 protected override void OnAccessKey(AccessKeyEventArgs e)
 {
     TargetLocationSearchTextBox.Focus();
 }
Exemple #11
0
 private void CommitSelectionAndMoveFocus()
 {
     Commit(SelectedItem);
     TargetLocationSearchTextBox.Focus();
 }
Exemple #12
0
 private void OnItemCommitGesture(object sender, MouseButtonEventArgs e)
 {
     Commit(SelectedItem);
     e.Handled = true;
     TargetLocationSearchTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
 }