// ************************************************************************ private void ResultsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { ListBoxResults.ScrollIntoView(ListBoxResults.Items[ListBoxResults.Items.Count - 1]); } }
protected override void OnPreviewKeyDown(KeyEventArgs e) { if (e.Key == App.Prefs.ActivationKey) { e.Handled = !_canTypeActivationKey; } base.OnPreviewKeyDown(e); if (e.Key == Key.Down) { if (TextBoxSearchBar.IsFocused) { if (ListBoxResults.HasItems) { ListBoxResults.SelectedIndex = 0; ListBoxResults.UpdateLayout(); var listBoxItem = (ListBoxItem)ListBoxResults .ItemContainerGenerator .ContainerFromItem(ListBoxResults.Items[0]); listBoxItem.Focus(); ListBoxResults.Items.Refresh(); ListBoxResults.ScrollIntoView(listBoxItem); } } if (ListBoxResults.SelectedIndex == ListBoxResults.Items.Count - 1) { e.Handled = true; } } else if (e.Key == Key.Up) { if (ListBoxResults.SelectedIndex == 0) { e.Handled = true; } } }