Dela via


SearchPane.SuggestionsRequested Event

Definition

Occurs when the user's query text changes and the app needs to provide new suggestions to display in the search pane.

/// [add: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.ApplicationModel.Search.SearchContract)]
/// [remove: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.ApplicationModel.Search.SearchContract)]
// Register
event_token SuggestionsRequested(TypedEventHandler<SearchPane, SearchPaneSuggestionsRequestedEventArgs const&> const& handler) const;

// Revoke with event_token
void SuggestionsRequested(event_token const* cookie) const;

// Revoke with event_revoker
SearchPane::SuggestionsRequested_revoker SuggestionsRequested(auto_revoke_t, TypedEventHandler<SearchPane, SearchPaneSuggestionsRequestedEventArgs const&> const& handler) const;
/// [add: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.ApplicationModel.Search.SearchContract")]
/// [remove: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.ApplicationModel.Search.SearchContract")]
// Register
event_token SuggestionsRequested(TypedEventHandler<SearchPane, SearchPaneSuggestionsRequestedEventArgs const&> const& handler) const;

// Revoke with event_token
void SuggestionsRequested(event_token const* cookie) const;

// Revoke with event_revoker
SearchPane::SuggestionsRequested_revoker SuggestionsRequested(auto_revoke_t, TypedEventHandler<SearchPane, SearchPaneSuggestionsRequestedEventArgs const&> const& handler) const;
[add: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.ApplicationModel.Search.SearchContract))]
[remove: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.ApplicationModel.Search.SearchContract))]
public event TypedEventHandler<SearchPane,SearchPaneSuggestionsRequestedEventArgs> SuggestionsRequested;
[add: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.ApplicationModel.Search.SearchContract")]
[remove: Windows.Foundation.Metadata.Deprecated("ISearchPane may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.ApplicationModel.Search.SearchContract")]
public event TypedEventHandler<SearchPane,SearchPaneSuggestionsRequestedEventArgs> SuggestionsRequested;
function onSuggestionsRequested(eventArgs) { /* Your code */ }
searchPane.addEventListener("suggestionsrequested", onSuggestionsRequested);
searchPane.removeEventListener("suggestionsrequested", onSuggestionsRequested);
- or -
searchPane.onsuggestionsrequested = onSuggestionsRequested;
Public Custom Event SuggestionsRequested As TypedEventHandler(Of SearchPane, SearchPaneSuggestionsRequestedEventArgs) 

Event Type

Attributes

Remarks

Important

To implement search in an app for Windows 10 or later, use AutoSuggestBox. See Auto-suggest box for more info.

You should not use Windows.ApplicationModel.Search APIs (SearchPane, SearchContract) or SearchBox APIs in apps for Windows 10 or later.

Note

An app can't use both the search box (Windows.UI.Xaml.Controls.SearchBox/WinJS.UI.SearchBox) and the SearchPane. Using both the search box and the search pane in the same app causes the app to throw an exception with this message: "Cannot create instance of type 'Windows.UI.Xaml.Controls.SearchBox.'"

Suggestions can come from three sources: search history, local files, or from a source specified by the app. Suggestions are grouped by their source and display in the following order in the search pane: search history, local files, and then app-specified sources.

If your app participates in the Search contract and you want your app to display suggestions from sources that you specify, you must register a handler to respond when this event fires. In your SuggestionsRequested event handler, respond by obtaining suggestions and populating the SearchSuggestionCollection based on the user's SearchPaneSuggestionsRequestedEventArgs.QueryText.

Note

If you want to respond to this event asynchronously, you must use SearchPaneSuggestionsRequestedEventArgs.Request.GetDeferral.

Suggestions can't be provided for an empty search box, so this event isn't fired when the user updates the search box to be empty.

Types of search suggestions

There are two types of suggestions your app can display: suggestions that help users refine a query (query suggestions), and suggestions that are actual results of a query (result suggestions). You may choose to display either or both types of suggestions.

If you provide query suggestions and the user selects one, your app should respond by displaying results for the selected, refined query in your app's search results page.

If you provide result suggestions, you must also register a ResultSuggestionChosen event handler so that you can respond when the user selects one of your result suggestions and you can display the result to the user.

Obtaining suggestions

Here are a few examples of sources your app can use to obtain suggestions:

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

Displaying app-provided suggestions in the search pane

After you obtain suggestions, you display them in the search pane by adding them to the Request.SearchSuggestionCollection.

At most, the search pane can display 5 suggestions. If you choose to display both query suggestions and result suggestions, you should group the suggestions by suggestion type (query or result) and separate the groups using AppendSearchSeparator. Each separator takes the place of a suggestion and must be followed by at least one suggestion, decreasing the number of suggestions that you can display.

Applies to

See also