-api-id | -api-type |
---|---|
E:Windows.UI.Xaml.Controls.SearchBox.QuerySubmitted |
winrt event |
Occurs when the user submits a search query.
<SearchBox QuerySubmitted="eventhandler"/>
Handle this event so that you can get the QueryText value from SearchBoxQuerySubmittedEventArgs, and pass it on as navigation data when you load a search results page to display to the user.
For a complete example of how to handle QuerySubmitted as part of a complete example that also does search suggestions, see SearchBox control sample.
The handler signature for QuerySubmitted uses TypedEventHandler and enforces that the sender parameter be a SearchBox instance, not just Object.
Here's a basic XAML definition for a SearchBox, and an implementation of the QuerySubmitted handler. It calls Frame.Navigate to load a search query result page (not shown) that's named SearchResultsPage1
. The this/Me reference in the handlers is the containing page instance, as is typical for on-page input event handling code. You can see similar code as part of Quickstart: Adding search to an app and Enabling users to search for information in your .
<SearchBox x:Name="mySearchBox"
FocusOnKeyboardInput="True"
QuerySubmitted="mySearchBox_QuerySubmitted"
Height="35" />
private void mySearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)
{
this.Frame.Navigate(typeof(SearchResultsPage1), args.QueryText);
}
Private Sub mySearchBox_QuerySubmitted(sender As SearchBox, args As SearchBoxQuerySubmittedEventArgs)
Me.Frame.Navigate(GetType(SearchResultsPage1), args.QueryText)
End Sub
SearchBoxQuerySubmittedEventArgs, Enabling users to search for information in your , Quickstart: Adding search to an app, SearchBox control sample