SearchBoxSuggestionsRequestedEventArgs SearchBoxSuggestionsRequestedEventArgs SearchBoxSuggestionsRequestedEventArgs SearchBoxSuggestionsRequestedEventArgs Class

Definition

Provides event data for the SearchBox.SuggestionsRequested event.

public : sealed class SearchBoxSuggestionsRequestedEventArgs
struct winrt::Windows::UI::Xaml::Controls::SearchBoxSuggestionsRequestedEventArgs
public sealed class SearchBoxSuggestionsRequestedEventArgs
Public NotInheritable Class SearchBoxSuggestionsRequestedEventArgs
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

If you want to respond to the SuggestionsRequested event asynchronously, you must obtain a SearchSuggestionsRequestDeferral object before you edit the suggestion list. Here's an example that shows how.

        public async static void SearchBox_SuggestionsRequested(
            SearchBox sender, 
            SearchBoxSuggestionsRequestedEventArgs args)
        {

            // This object lets us edit the SearchSuggestionCollection asynchronously. 
            var deferral = args.Request.GetDeferral();

            try { 

                // Retrieve the system-supplied suggestions.
                var suggestions = args.Request.SearchSuggestionCollection;
           
                var groups = await SampleDataSource.GetGroupsAsync();
                foreach (var group in groups)
                {
                    var matchingItems = group.Items.Where(
                        item => item.Title.StartsWith(
                            args.QueryText, StringComparison.CurrentCultureIgnoreCase));

                    foreach (var item in matchingItems)
                    {
                        suggestions.AppendQuerySuggestion(item.Title);
                    }
                }
            
                foreach (string alternative in args.LinguisticDetails.QueryTextAlternatives)
                {
                    if (alternative.StartsWith(
                        args.QueryText, StringComparison.CurrentCultureIgnoreCase))
                    {
                        suggestions.AppendQuerySuggestion(alternative); 
                    }
                }
            }
            finally {
                deferral.Complete();
            }

        }

Remarks

Important

Although SearchBox is implemented in the Universal device family, it is not fully functional on mobile devices. Use AutoSuggestBox for your universal search experience. See SearchBox deprecated in favor of AutoSuggestBox.

Properties

Language Language Language Language

Gets the Internet Engineering Task Force (IETF) language tag (BCP 47 standard) that identifies the language currently associated with the user's text input device.

LinguisticDetails LinguisticDetails LinguisticDetails LinguisticDetails

Gets information about query text that the user enters through an Input Method Editor (IME).

QueryText QueryText QueryText QueryText

Gets the query text of the current search.

Request Request Request Request

Gets the object that stores the suggestions and information about this request.

See also