/// <summary> /// Populates SearchBox with Suggestions when user enters text /// </summary> /// <param name="sender">Xaml SearchBox</param> /// <param name="e">Event when user changes text in SearchBox</param> private void SearchBoxEventsSuggestionsRequested(object sender, SearchBoxSuggestionsRequestedEventArgs e) { string queryText = e.QueryText; if (!string.IsNullOrEmpty(queryText)) { Windows.ApplicationModel.Search.SearchSuggestionCollection suggestionCollection = e.Request.SearchSuggestionCollection; foreach (string suggestion in suggestionList) { if (suggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) { suggestionCollection.AppendQuerySuggestion(suggestion); } } } if (e.Request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } }
/// <summary> /// Populates SearchBox with Suggestions when user enters text /// </summary> /// <param name="sender">The Xaml SearchBox</param> /// <param name="args">Event when user changes text in SearchBox</param> private async void SearchBoxEventsSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args) { string queryText = args.QueryText; if (string.IsNullOrEmpty(queryText)) { return; } Windows.ApplicationModel.Search.SearchSuggestionCollection suggestionCollection = args.Request.SearchSuggestionCollection; if (this.suggestionList == null) { this.suggestionList = await DataManager.JobDataSource.GetAllJobs(); } foreach (var suggestion in this.suggestionList) { if (suggestion.Title.ToUpper().Contains(queryText.ToUpper())) { suggestionCollection.AppendQuerySuggestion(suggestion.Title); } if (suggestion.Id.Contains(queryText)) { suggestionCollection.AppendQuerySuggestion(suggestion.Id); } if (suggestion.Customer.FullName.ToUpper().Contains(queryText.ToUpper())) { suggestionCollection.AppendQuerySuggestion(suggestion.Customer.FullName); } } }