Ejemplo n.º 1
0
        /// <summary>
        /// Handles a key press. Used to let the completion list handle key presses while the
        /// focus is still on the text editor.
        /// </summary>
        public void HandleKey(KeyEventArgs e)
        {
            if (listBox == null)
            {
                return;
            }

            // We have to do some key handling manually, because the default doesn't work with
            // our simulated events.
            // Also, the default PageUp/PageDown implementation changes the focus, so we avoid it.
            switch (e.Key)
            {
            case Key.Down:
                e.Handled = true;
                listBox.SelectIndex(listBox.SelectedIndex + 1);
                break;

            case Key.Up:
                e.Handled = true;
                listBox.SelectIndex(listBox.SelectedIndex - 1);
                break;

            case Key.PageDown:
                e.Handled = true;
                listBox.SelectIndex(
                    listBox.SelectedIndex + listBox.VisibleItemCount);
                break;

            case Key.PageUp:
                e.Handled = true;
                listBox.SelectIndex(
                    listBox.SelectedIndex - listBox.VisibleItemCount);
                break;

            case Key.Home:
                e.Handled = true;
                listBox.SelectIndex(0);
                break;

            case Key.End:
                e.Handled = true;
                listBox.SelectIndex(listBox.Items.Count - 1);
                break;

            case Key.Tab:
            case Key.Enter:
                e.Handled = true;
                RequestInsertion(e);
                break;
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            listBox = GetTemplateChild("PART_ListBox") as CompletionListBox;
            if (listBox != null)
            {
                listBox.ItemsSource = completionData;

                if (completionData.Count > 0)
                {
                    listBox.SelectIndex(0);
                }
            }
        }