SearchPaneSuggestionsRequestedEventArgs class

Applies to Windows only

Provides data for a suggestionsrequested event that is associated with a searchPane object.

Syntax


public sealed class SearchPaneSuggestionsRequestedEventArgs : ISearchPaneQueryChangedEventArgs

Attributes

[MarshalingBehavior(Agile)]
[Version(0x06020000)]

Members

The SearchPaneSuggestionsRequestedEventArgs class has these types of members:

Properties

The SearchPaneSuggestionsRequestedEventArgs class has these properties.

PropertyAccess typeDescription

Language

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

LinguisticDetails

Read-onlyAn object that provides linguistic information about query text that the user is entering through an Input Method Editor (IME).

QueryText

Read-onlyThe text that the app should provide suggestions for and that was in the search box when the suggestionsrequested event fired.

Request

Read-onlyAn object that stores suggestions and information about the request.

 

Remarks

This object is passed to an app's suggestionsrequested event handler.

Use your app to provide suggestions

There are a few different ways you can get suggestions for your app to provide:

  • From an app-defined, static, local list
  • From a URL that supports suggestions in OpenSearch format
  • From a URL that supports suggestions in XML format

After you obtain suggestions, you must append them to the collection of suggestions to display for the user's query. Access this collection with the searchPaneSuggestionsRequest.searchSuggestionCollection property.

Note  If you want to provide result suggestions, you must also listen for and handle the resultsuggestionchosen event.

Examples

The Search contract sample demonstrates how to respond to a suggestionsrequested event.

Note  You can access information about the event from the searchPaneSuggestionsRequestedEventArgs object that is passed to your suggestionsrequested handler.


private void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e)
{
    var queryText = e.QueryText;
    if (string.IsNullOrEmpty(queryText))
    {
        MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage);
    }
    else
    {
        var request = e.Request;
        var linguisticDetails = e.LinguisticDetails;
        foreach (string alternative in linguisticDetails.QueryTextAlternatives)
        {
            foreach (string suggestion in suggestionList)
            {
                if (suggestion.StartsWith(alternative, StringComparison.CurrentCultureIgnoreCase))
                {
                    // Add suggestion to Search Pane
                    request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion);

                    // Break since the Search Pane can show at most 5 suggestions
                    if (request.SearchSuggestionCollection.Size >= MainPage.SearchPaneMaxSuggestions)
                    {
                        break;
                    }
                }
            }

            // Break since the Search Pane can show at most 5 suggestions
            if (request.SearchSuggestionCollection.Size >= MainPage.SearchPaneMaxSuggestions)
            {
                break;
            }
        }

        if (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);
        }
    }
}


For C# developers, the Search contract sample also demonstrates how to register for a SuggestionsRequested event through the SearchPane.


searchPane.SuggestionsRequested += new TypedEventHandler<SearchPane, SearchPaneSuggestionsRequestedEventArgs>(OnSearchPaneSuggestionsRequested);

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported

Namespace

Windows.ApplicationModel.Search
Windows::ApplicationModel::Search [C++]

Metadata

Windows.winmd

See also

Search contract sample
Guidelines and checklist for search
Reference
SearchPane class
SearchPane.ResultSuggestionChosen event
SearchPane.SuggestionsRequested event
SearchSuggestionCollection class
SearchPaneSuggestionsRequestedEventArgs class
SearchPaneSuggestionsRequest.SearchSuggestionCollection property

 

 

Show:
© 2014 Microsoft