Windows.UI.Xaml.Controls.SearchBox
November 30, 2023 · View on GitHub
-description
Represents a control that can be used to enter search query text. (Not recommended for Universal Windows Platform (UWP) apps. See AutoSuggestBox.)
-xaml-syntax
<SearchBox .../>
-remarks
Use AutoSuggestBox for search.
Notes for previous versions
Windows 10 or later
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.
Windows 8.x
To support keyboard interaction and make your app's search experience consistent with the Start screen, set the FocusOnKeyboardInput property to true. For more info, see Guidelines and checklist for search.
At a minimum each SearchBox control should always have a QuerySubmitted handler. This handler passes the user's query text to a search results page that the handler opens. Open this page by calling Frame.Navigate. For more info on how to write a basic QuerySubmitted handler and create a search results page as part of your app, see Enabling users to search for information in your .
In addition to the basic results and search experience, a SearchBox also supports search suggestions, programmatically setting the starting search text, and search history. The search suggestion feature is supported by API in the Windows.ApplicationModel.Search namespace. For example code that shows how to use these features, see SearchBox control sample.
Note
An app can't use both the search box 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'"
-examples
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.
<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
-see-also
Quickstart: Adding search to an app, Control, SearchBoxQuerySubmittedEventArgs, SearchBox control sample, Enabling users to search for information in your