private async Task SearchBoxSuggestionsRequested(SearchBoxSuggestionsRequestedEventArgs args) { var queryText = args.QueryText != null?args.QueryText.Trim() : null; if (string.IsNullOrEmpty(queryText)) { return; } var deferral = args.Request.GetDeferral(); try { var suggestionCollection = args.Request.SearchSuggestionCollection; var querySuggestions = await _productCatalogRepository.GetSearchSuggestionsAsync(queryText); if (querySuggestions != null && querySuggestions.Count > 0) { var querySuggestionCount = 0; foreach (string suggestion in querySuggestions) { querySuggestionCount++; suggestionCollection.AppendQuerySuggestion(suggestion); if (querySuggestionCount >= MaxNumberOfSuggestions) { break; } } } } catch (Exception) { // Ignore any exceptions that occur trying to find search suggestions. } deferral.Complete(); }