private void _input_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (SuggestEngine != null)
     {
         Suggestions = SuggestEngine.GetSuggestionsFor(Input.Text);
         if (PrevText != Input.Text && IsKeyboardFocusWithin)
         {
             if (Suggestions.Count() > 0)
             {
                 Popup.IsOpen = true;
             }
             else
             {
                 Popup.IsOpen = false;
             }
             PrevText = Input.Text;
             if (Selected != null)
             {
                 Selected = null;
             }
         }
         else
         {
             if (!IsKeyboardFocusWithin)
             {
                 ChangedInBackground = true;
                 Selected            = null;
             }
         }
     }
 }
 private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (ListBox.IsKeyboardFocusWithin && ListBox.SelectedIndex >= 0)
     {
         var selected = ListBox.SelectedItem;
         PrevText   = SuggestEngine.ToText(selected);
         Input.Text = PrevText;
         Input.Focus();
         Input.CaretIndex = Input.Text.Length;
         Popup.IsOpen     = false;
         Selected         = selected;
     }
 }
        private void ListBox_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var selected = ListBox.SelectedItem;

            if (selected != null)
            {
                PrevText   = SuggestEngine.ToText(selected);
                Input.Text = PrevText;
                Input.Focus();
                Input.CaretIndex = Input.Text.Length;
                Popup.IsOpen     = false;
                Selected         = selected;
            }
        }
 private void _input_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Down)
     {
         if (Popup.IsOpen)
         {
             var index = ListBox.SelectedIndex;
             if (index < 0)
             {
                 ListBox.SelectedIndex = 0;
             }
             else
             {
                 var d = ListBox.SelectedItemProperty;
                 if (index + 1 < ListBox.Items.Count)
                 {
                     ListBox.SelectedIndex = index + 1;
                     Scroll.ScrollToVerticalOffset(Scroll.ContentVerticalOffset + offset());
                 }
             }
         }
         e.Handled = true;
     }
     if (e.Key == Key.Up)
     {
         if (Popup.IsOpen)
         {
             var index = ListBox.SelectedIndex;
             if (index > 0)
             {
                 ListBox.SelectedIndex = index - 1;
             }
             Scroll.ScrollToVerticalOffset(Scroll.ContentVerticalOffset - offset());
         }
         e.Handled = true;
     }
     if (e.Key == Key.PageDown)
     {
         if (Popup.IsOpen)
         {
             ListBox.SelectedIndex = ListBox.Items.Count - 1;
             Scroll.ScrollToBottom();
         }
         e.Handled = true;
     }
     if (e.Key == Key.PageUp)
     {
         if (Popup.IsOpen)
         {
             ListBox.SelectedIndex = 0;
             Scroll.ScrollToTop();
         }
         e.Handled = true;
     }
     if (e.Key == Key.Enter)
     {
         if (Popup.IsOpen)
         {
             var selected = ListBox.SelectedItem;
             if (selected != null)
             {
                 PrevText   = SuggestEngine.ToText(selected);
                 Input.Text = PrevText;
                 Input.Focus();
                 Input.CaretIndex = Input.Text.Length;
             }
             Popup.IsOpen = false;
             Selected     = selected;
         }
         e.Handled = true;
     }
     if (e.Key == Key.Escape)
     {
         if (Popup.IsOpen)
         {
             Popup.IsOpen = false;
         }
     }
 }