protected override void OnAppearing() { base.OnAppearing(); // Hide cancel button on iOS since it has its own. if (Device.RuntimePlatform == Device.iOS) { SearchSearchBar.WidthRequest = Width; } if (Device.RuntimePlatform == Device.UWP) { SearchSearchBar.HeightRequest = 35; SearchSearchBar.WidthRequest = Width; } if (_viewModel.SearchResults.Count == 0) { // Focus the search bar so keyboard pops up. SearchSearchBar.Focus(); } // To workaround problem with initial progress color. SearchResultListView.BeginRefresh(); SearchResultListView.EndRefresh(); }
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (this.Visibility != Visibility.Visible) { e.Handled = true; return; } if (Keyboard.Modifiers == ModifierKeys.Alt) { e.Handled = true; return; } switch (e.Key) { case Key.LeftAlt: case Key.RightAlt: { e.Handled = true; break; } case Key.Tab: /*open the search filter list if it's closed, otherwise cycle through the options*/ { if (SearchFilterList.Visibility == Visibility.Collapsed) { SearchFilterList.Visibility = Visibility.Visible; } else { if (SearchFilterList.SelectedIndex == SearchFilterList.Items.Count - 1) { SearchFilterList.SelectedIndex = 0; } else { SearchFilterList.SelectedIndex++; } } e.Handled = true; break; } case Key.Escape: { SearchBox.Text = ""; SearchFilterList.Visibility = Visibility.Collapsed; break; } case Key.Up: { if (SearchResultListView.Items.Count > 0) { if (SearchResultListView.SelectedIndex > 0) { SearchResultListView.SelectedIndex = SearchResultListView.SelectedIndex - 1; } SearchResultListView.ScrollIntoView(SearchResultListView.SelectedItem); } e.Handled = true; break; } case Key.Down: { if (SearchResultListView.Items.Count > 0) { if (SearchResultListView.SelectedIndex < SearchResultListView.Items.Count - 1) { SearchResultListView.SelectedIndex = SearchResultListView.SelectedIndex + 1; } SearchResultListView.ScrollIntoView(SearchResultListView.SelectedItem); } e.Handled = true; break; } default: { SearchFilterList.Visibility = Visibility.Collapsed; break; } } if (SearchBox.IsFocused == false) { SearchBox.Focus(); } }