XAML - SearchBox

A SearchBox represents a control that can be used to enter search query text. WPF projects do not support SearchBox, so it will be implemented in Windows App. The hierarchical inheritance of SearchBox class is as follow −
PlaceholderText
Gets or sets the text that is displayed in the control until the value is changed by a user action or some other operation.
ChooseSuggestionOnEnter
Gets or sets a value that determines whether the suggested search query is activated when the user presses Enter.
ChooseSuggestionOnEnterProperty
Identifies the ChooseSuggestionOnEnter dependency property.
FocusOnKeyboardInput
Gets or sets a value that determines whether a user can search by typing anywhere in the app.
FocusOnKeyboardInputProperty
Identifies the FocusOnKeyboardInput dependency property.
PlaceholderTextProperty
Identifies the PlaceholderText dependency property.
QueryText
Gets or sets the text contents of the search box.
QueryTextProperty
Identifies the QueryText dependency property.
SearchHistoryContext
Gets or sets a string that identifies the context of the search and is used to store the user's search history with the app.
SearchHistoryContextProperty
Identifies the SearchHistoryContext dependency property.
SearchHistoryEnabled
Gets or sets a value that determines whether search suggestions are made from the search history.
SearchHistoryEnabledProperty
Identifies the SearchHistoryEnabled dependency property.
PrepareForFocusOnKeyboardInput
Occurs when the FocusOnKeyboardInput property is true and the app receives textual keyboard input.
QueryChanged
Occurs when the query text changes.
QuerySubmitted
Occurs when the user submits a search query.
ResultSuggestionChosen
Occurs when the user picks a suggested search result.
SuggestionsRequested
Occurs when the user's query text changes and the app needs to provide new suggestions to display in the search pane.
OnManipulationCompleted
Called before the ManipulationCompleted event occurs. (Inherited from Control)
OnManipulationDelta
Called before the ManipulationDelta event occurs. (Inherited from Control)
OnManipulationInertiaStarting
Called before the ManipulationInertiaStarting event occurs. (Inherited from Control)
OnManipulationStarted
Called before the ManipulationStarted event occurs. (Inherited from Control)
OnManipulationStarting
Called before the ManipulationStarting event occurs. (Inherited from Control)
OnMaximumChanged
Called when the Maximum property changes. (Inherited from RangeBase)
OnMinimumChanged
Called when the Minimum property changes. (Inherited from RangeBase)
OnValueChanged
Fires the ValueChanged routed event. (Inherited from RangeBase)
SetBinding
Attaches a binding to a FrameworkElement, using the provided binding object. (Inherited from FrameworkElement)
SetLocalContentSuggestionSettings
Specifies whether suggestions based on local files are automatically displayed in the search box suggestions, and defines the criteria that Windows uses to locate and filter these suggestions.
SetValue
Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)
StartDragAsync
Initiates a drag-and-drop operation. (Inherited from UIElement)
UnregisterPropertyChangedCallback
Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback. (Inherited from DependencyObject)
The following example shows the usage of SearchBox in an XAML application. Here is the XAML code to create and initialize a SearchBox with some properties and events.
<Page x:Class = "XAML_SearchBox.MainPage" 
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local = "using:XAML_SearchBox" 
   xmlns:d = "http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
   mc:Ignorable = "d">
	
   <Grid Background = "{ThemeResource ApplicationPageBackgroundThemeBrush}">
      <SearchBox x:Name = "mySearchBox"
         FocusOnKeyboardInput = "False"
         QuerySubmitted = "mySearchBox_QuerySubmitted" 
         Height = "35" Width = "400" Margin = "234,132,732,601"/>
   </Grid> 
	
</Page>
Here is the implementation in C# for search query −
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Runtime.InteropServices.WindowsRuntime; 

using Windows.Foundation; 
using Windows.Foundation.Collections;

using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Controls.Primitives; 
using Windows.UI.Xaml.Data; 
using Windows.UI.Xaml.Input; 
using Windows.UI.Xaml.Media; 
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace XAML_SearchBox { 
   /// <summary> 
      /// An empty page that can be used on its own or navigated to within a Frame. 
   /// </summary> 
	
   public sealed partial class MainPage : Page {
      public MainPage() { 
         this.InitializeComponent(); 
      } 
      private void mySearchBox_QuerySubmitted(SearchBox sender,
         SearchBoxQuerySubmittedEventArgs args) { 
         
         this.Frame.Navigate(typeof(SearchResultsPage1), args.QueryText);
      } 
   }
}
In Windows App project for this example, add a Search Results Page with the name SearchResultsPage1.xaml. The default implementation is sufficient to run this App.
When you compile and execute the above code, it will produce the following output −
We recommend you to execute the above example code and experiment with some other properties and events.