AutoSuggestBox
AutoSuggestBox
AutoSuggestBox
AutoSuggestBox
Class
Definition
Represents a text control that makes suggestions to users as they type. The app is notified when text has been changed by the user and is responsible for providing relevant suggestions for this control to display.
public : sealed class AutoSuggestBox : ItemsControl, IAutoSuggestBox, IAutoSuggestBox2, IAutoSuggestBox3public sealed class AutoSuggestBox : ItemsControl, IAutoSuggestBox, IAutoSuggestBox2, IAutoSuggestBox3Public NotInheritable Class AutoSuggestBox Inherits ItemsControl Implements IAutoSuggestBox, IAutoSuggestBox2, IAutoSuggestBox3// This API is not available in Javascript.
<AutoSuggestBox .../>
- Inheritance
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Inherited Members
Inherited properties
Inherited events
Inherited methods
Examples
To see a complete working example of AutoSuggestBox, see the AutoSuggestBox migration sample.
Here is a simple AutoSuggestBox with the required event handlers.
<AutoSuggestBox PlaceholderText="Search" QueryIcon="Find" Width="200"
TextChanged="AutoSuggestBox_TextChanged"
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
SuggestionChosen="AutoSuggestBox_SuggestionChosen"/>
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
// Only get results when it was a user typing,
// otherwise assume the value got filled in by TextMemberPath
// or the handler for SuggestionChosen.
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
//Set the ItemsSource to be your filtered dataset
//sender.ItemsSource = dataset;
}
}
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
// Set sender.Text. You can use args.SelectedItem to build your text string.
}
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (args.ChosenSuggestion != null)
{
// User selected an item from the suggestion list, take an action on it here.
}
else
{
// Use args.QueryText to determine what to do.
}
}
Remarks
Use an AutoSuggestBox to provide a list of suggestions for a user to select from as they type.
By default, the text entry box doesn’t have a query button shown. You can set the QueryIcon property to add a button with the specified icon on the right side of the text box. For example, to make the AutoSuggestBox look like a typical search box, add a ‘find’ icon, like this.
<AutoSuggestBox QueryIcon="Find"/>
Here's an AutoSuggestBox with a 'find' icon. The suggestion list shows suggested results based on the user's entry.
To use an AutoSuggestBox, you need to respond to 3 user actions.
- Text changed - When the user enters text, update the suggestion list.
- Suggestion chosen - When the user chooses a suggestion in the suggestion list, update the text box.
- Query submitted - When the user submits a query, show the query results.
Text changed
The TextChanged event occurs whenever the content of the text box is updated. Use the event args Reason property to determine whether the change was due to user input. If the change reason is UserInput, filter your data based on the input. Then, set the filtered data as the ItemsSource of the AutoSuggestBox to update the suggestion list.
To control how items are displayed in the suggestion list, you can use DisplayMemberPath or ItemTemplate.
- To display the text of a single property of your data item, set the DisplayMemberPath property to choose which property from your object to display in the suggestion list.
- To define a custom look for each item in the list, use the ItemTemplate property .
Suggestion chosen
When a user navigates through the suggestion list using the keyboard, you need to update the text in the text box to match.
You can set the TextMemberPath property to choose which property from your data object to display in the text box. If you specify a TextMemberPath, the text box is updated automatically. You should typically specify the same value for DisplayMemberPath and TextMemberPath so the text is the same in the suggestion list and the text box.
If you need to show more than a simple property, handle the SuggestionChosen event to populate the text box with custom text based on the selected item.
Query submitted
Handle the QuerySubmitted event to perform a query action appropriate to your app and show result to the user.
The QuerySubmitted event occurs when a user commits a query string. The user can commit a query in one of these ways:
- While focus is in the text box, press Enter or click the query icon. The event args ChosenSuggestion property is null.
- While focus is in the suggestion list, press Enter, click, or tap an item. The event args ChosenSuggestion property contains the item that was selected from the list. In all cases, the event args QueryText property contains the text from the text box.
Accessibility
If you are using an assistive technology, such as Narrator, to interact with the AutoSuggestBox the accessibility experience has already been hooked up for you. A user will:
- Know the list is present and when the list closes
- Know how many suggestions are available
- Be able to move Narrator focus to the list
- Be able to Navigate through a suggestion with all other reading modes See Auto-suggest accessibility for more information.
Control style and template
You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see Styling controls. The default style, template, and resources that define the look of the control are included in the generic.xaml file. For design purposes, generic.xaml is available in the (Program Files)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP<SDK version>\Generic folder from a Windows Software Development Kit (SDK) installation. Styles and resources from different versions of the SDK might have different values.
Starting in Windows 10, version 1607 (Windows Software Development Kit (SDK) version 10.0.14393.0), generic.xaml includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. In apps that target this software development kit (SDK) or later, modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the Styling controls article.
This table shows the resources used by the AutoSuggestBox control. Resources that start with "TextControl" are shared by TextBox, PasswordBox, RichEditBox, and AutoSuggestBox.
| Resource key | Description |
|---|---|
| AutoSuggestBoxSuggestionsListBackground | Background color of suggestion list |
| AutoSuggestBoxSuggestionsListBorderBrush | Border color of suggestion list |
| TextControlForeground | Text color at rest |
| TextControlForegroundPointerOver | Text color on hover |
| TextControlForegroundFocused | Text color when focused |
| TextControlForegroundDisabled | Text color when disabled |
| TextControlBackground | Background color at rest |
| TextControlBackgroundPointerOver | Background color on hover |
| TextControlBackgroundFocused | Background color when focused |
| TextControlBackgroundDisabled | Background color when disabled |
| TextControlBorderBrush | Border color at rest |
| TextControlBorderBrushPointerOver | Border color on hover |
| TextControlBorderBrushFocused | Border color when focused |
| TextControlBorderBrushDisabled | Border color when disabled |
| TextControlPlaceholderForeground | Placeholder text color at rest |
| TextControlPlaceholderForegroundPointerOver | Placeholder text color on hover |
| TextControlPlaceholderForegroundFocused | Placeholder text color when focused |
| TextControlPlaceholderForegroundDisabled | Placeholder text color when disabled |
| TextControlHeaderForeground | Header text color at rest |
| TextControlHeaderForegroundDisabled | Header text color when disabled |
| TextControlSelectionHighlightColor | Highlight color of selected text |
| TextControlButtonBackground | Background color of delete button at rest |
| TextControlButtonBackgroundPointerOver | Background color of delete button on hover |
| TextControlButtonBackgroundPressed | Background color of delete button when pressed |
| TextControlButtonBorderBrush | Border color of delete button at rest |
| TextControlButtonBorderBrushPointerOver | Border color of delete button on hover |
| TextControlButtonBorderBrushPressed | Border color of delete button when pressed |
| TextControlButtonForeground | Foreground color of delete button at rest |
| TextControlButtonForegroundPointerOver | Foreground color of delete button on hover |
| TextControlButtonForegroundPressed | Foreground color of delete button when pressed |
Constructors
AutoSuggestBox() AutoSuggestBox() AutoSuggestBox() AutoSuggestBox()
Initializes a new instance of the AutoSuggestBox class.
public : AutoSuggestBox()public AutoSuggestBox()Public Sub New()// This API is not available in Javascript.
Properties
AutoMaximizeSuggestionArea AutoMaximizeSuggestionArea AutoMaximizeSuggestionArea AutoMaximizeSuggestionArea
Indicates if the suggestion area should be automatically maximized.
public : PlatForm::Boolean AutoMaximizeSuggestionArea { get; set; }public bool AutoMaximizeSuggestionArea { get; set; }Public ReadWrite Property AutoMaximizeSuggestionArea As bool// This API is not available in Javascript.
<AutoSuggestBox AutoMaximizeSuggestionArea="bool"/>
- Value
- PlatForm::Boolean bool bool bool
A Boolean value that indicates if the suggestion area should be automatically maximized.
AutoMaximizeSuggestionAreaProperty AutoMaximizeSuggestionAreaProperty AutoMaximizeSuggestionAreaProperty AutoMaximizeSuggestionAreaProperty
Identifies the AutoMaximizeSuggestionArea dependency property.
public : static DependencyProperty AutoMaximizeSuggestionAreaProperty { get; }public static DependencyProperty AutoMaximizeSuggestionAreaProperty { get; }Public Static ReadOnly Property AutoMaximizeSuggestionAreaProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the AutoMaximizeSuggestionArea dependency property.
Header Header Header Header
Gets or sets the header object for the text box portion of this control.
public : PlatForm::Object Header { get; set; }public object Header { get; set; }Public ReadWrite Property Header As object// This API is not available in Javascript.
<AutoSuggestBox Header="headerString"/>
- Value
- PlatForm::Object object object object
The header object for the text box portion of this control.
HeaderProperty HeaderProperty HeaderProperty HeaderProperty
Identifies the Header dependency property.
public : static DependencyProperty HeaderProperty { get; }public static DependencyProperty HeaderProperty { get; }Public Static ReadOnly Property HeaderProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the Header dependency property.
IsSuggestionListOpen IsSuggestionListOpen IsSuggestionListOpen IsSuggestionListOpen
Gets or sets a Boolean value indicating whether the drop-down portion of the AutoSuggestBox is open.
public : PlatForm::Boolean IsSuggestionListOpen { get; set; }public bool IsSuggestionListOpen { get; set; }Public ReadWrite Property IsSuggestionListOpen As bool// This API is not available in Javascript.
- Value
- PlatForm::Boolean bool bool bool
A Boolean value indicating whether the drop-down portion of the AutoSuggestBox is open.
Remarks
Do not set IsSuggestionListOpen in XAML. It's a state property for runtime interactions, and values set in XAML are ignored.
IsSuggestionListOpenProperty IsSuggestionListOpenProperty IsSuggestionListOpenProperty IsSuggestionListOpenProperty
Identifies the IsSuggestionListOpen dependency property.
public : static DependencyProperty IsSuggestionListOpenProperty { get; }public static DependencyProperty IsSuggestionListOpenProperty { get; }Public Static ReadOnly Property IsSuggestionListOpenProperty As DependencyProperty// This API is not available in Javascript.
Identifier for the IsSuggestionListOpen dependency property.
LightDismissOverlayMode LightDismissOverlayMode LightDismissOverlayMode LightDismissOverlayMode
Gets or sets a value that specifies whether the area outside of a light-dismiss UI is darkened.
public : LightDismissOverlayMode LightDismissOverlayMode { get; set; }public LightDismissOverlayMode LightDismissOverlayMode { get; set; }Public ReadWrite Property LightDismissOverlayMode As LightDismissOverlayMode// This API is not available in Javascript.
- Value
- LightDismissOverlayMode LightDismissOverlayMode LightDismissOverlayMode LightDismissOverlayMode
A value of the enumeration that specifies whether the area outside of a light-dismiss UI is darkened. The default is Auto.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
Remarks
Transient UI, such as the suggestion pane of an AutoSuggestBox, closes when you click or tap outside of it. This is called light-dismiss. "Overlay" refers to the area outside of a light-dismiss UI.
By default, the "overlay" is darkened on the Xbox, and not darkened on other devices families. You can set LightDismissOverlayMode to On to make your app darken the "overlay" area on all device families, or set it to Off to not darken the "overlay" area on all device families.
Version compatibility
The LightDismissOverlayMode property is not available prior to Windows 10, version 1607. If your app’s 'minimum platform version' setting in Microsoft Visual Studio is less than the 'introduced version' shown in the Requirements block later in this page, you must design and test your app to account for this. For more info, see Version adaptive code.
To avoid exceptions when your app runs on previous versions of Windows 10, do not set this property in XAML or use it without performing a runtime check. This example shows how to use the ApiInformation class to check for the presence of this property before you set it.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.AutoSuggestBox", "LightDismissOverlayMode"))
{
autoSuggestBox1.LightDismissOverlayMode = LightDismissOverlayMode.On;
}
}
LightDismissOverlayModeProperty LightDismissOverlayModeProperty LightDismissOverlayModeProperty LightDismissOverlayModeProperty
Identifies the LightDismissOverlayMode dependency property.
public : static DependencyProperty LightDismissOverlayModeProperty { get; }public static DependencyProperty LightDismissOverlayModeProperty { get; }Public Static ReadOnly Property LightDismissOverlayModeProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the LightDismissOverlayMode dependency property.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
MaxSuggestionListHeight MaxSuggestionListHeight MaxSuggestionListHeight MaxSuggestionListHeight
Gets or set the maximum height for the drop-down portion of the AutoSuggestBox control.
public : double MaxSuggestionListHeight { get; set; }public double MaxSuggestionListHeight { get; set; }Public ReadWrite Property MaxSuggestionListHeight As double// This API is not available in Javascript.
<AutoSuggestBox MaxSuggestionListHeight="double"/>
- Value
- double double double double
The maximum height for the drop-down portion of the AutoSuggestBox control.
MaxSuggestionListHeightProperty MaxSuggestionListHeightProperty MaxSuggestionListHeightProperty MaxSuggestionListHeightProperty
Identifies the MaxSuggestionListHeight dependency property.
public : static DependencyProperty MaxSuggestionListHeightProperty { get; }public static DependencyProperty MaxSuggestionListHeightProperty { get; }Public Static ReadOnly Property MaxSuggestionListHeightProperty As DependencyProperty// This API is not available in Javascript.
Identifier for the MaxSuggestionListHeight dependency property.
PlaceholderText PlaceholderText PlaceholderText PlaceholderText
Gets or sets the placeholder text to be displayed in the control.
public : PlatForm::String PlaceholderText { get; set; }public string PlaceholderText { get; set; }Public ReadWrite Property PlaceholderText As string// This API is not available in Javascript.
<AutoSuggestBox PlaceholderText="string"/>
- Value
- PlatForm::String string string string
The placeholder text to be displayed in the control. The default is an empty string.
PlaceholderTextProperty PlaceholderTextProperty PlaceholderTextProperty PlaceholderTextProperty
Identifies the PlaceholderText dependency property.
public : static DependencyProperty PlaceholderTextProperty { get; }public static DependencyProperty PlaceholderTextProperty { get; }Public Static ReadOnly Property PlaceholderTextProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the PlaceholderText dependency property.
QueryIcon QueryIcon QueryIcon QueryIcon
Gets or sets the graphic content of the button that is clicked to initiate a query.
public : IconElement QueryIcon { get; set; }public IconElement QueryIcon { get; set; }Public ReadWrite Property QueryIcon As IconElement// This API is not available in Javascript.
<AutoSuggestBox QueryIcon="symbolName" .../>
The graphic content of the button that is clicked to initiate a query, if present; otherwise, null. The default is null.
QueryIconProperty QueryIconProperty QueryIconProperty QueryIconProperty
Identifies the QueryIcon dependency property.
public : static DependencyProperty QueryIconProperty { get; }public static DependencyProperty QueryIconProperty { get; }Public Static ReadOnly Property QueryIconProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the QueryIcon dependency property.
Text Text Text Text
Gets or sets the text that is shown in the control.
public : PlatForm::String Text { get; set; }public string Text { get; set; }Public ReadWrite Property Text As string// This API is not available in Javascript.
- Value
- PlatForm::String string string string
The text that is shown in the control.
Remarks
This property is not typically set in XAML.
TextBoxStyle TextBoxStyle TextBoxStyle TextBoxStyle
Gets or sets the style of the auto-suggest text box.
public : Style TextBoxStyle { get; set; }public Style TextBoxStyle { get; set; }Public ReadWrite Property TextBoxStyle As Style// This API is not available in Javascript.
<AutoSuggestBox TextBoxStyle={StaticResource styleResourceKey}/>
TextBoxStyleProperty TextBoxStyleProperty TextBoxStyleProperty TextBoxStyleProperty
Identifies the TextBoxStyle dependency property.
public : static DependencyProperty TextBoxStyleProperty { get; }public static DependencyProperty TextBoxStyleProperty { get; }Public Static ReadOnly Property TextBoxStyleProperty As DependencyProperty// This API is not available in Javascript.
Identifier for the TextBoxStyle dependency property.
TextMemberPath TextMemberPath TextMemberPath TextMemberPath
Gets or sets the property path that is used to get the value for display in the text box portion of the AutoSuggestBox control, when an item is selected.
public : PlatForm::String TextMemberPath { get; set; }public string TextMemberPath { get; set; }Public ReadWrite Property TextMemberPath As string// This API is not available in Javascript.
<AutoSuggestBox TextMemberPath="propertyName"/>
- Value
- PlatForm::String string string string
The property path that is used to get the value for display in the text box portion of the AutoSuggestBox control, when an item is selected.
TextMemberPathProperty TextMemberPathProperty TextMemberPathProperty TextMemberPathProperty
Identifies the TextMemberPath dependency property.
public : static DependencyProperty TextMemberPathProperty { get; }public static DependencyProperty TextMemberPathProperty { get; }Public Static ReadOnly Property TextMemberPathProperty As DependencyProperty// This API is not available in Javascript.
Identifier for the TextMemberPath dependency property.
TextProperty TextProperty TextProperty TextProperty
Identifies the PlaceholderText dependency property.
public : static DependencyProperty TextProperty { get; }public static DependencyProperty TextProperty { get; }Public Static ReadOnly Property TextProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the PlaceholderText dependency property.
UpdateTextOnSelect UpdateTextOnSelect UpdateTextOnSelect UpdateTextOnSelect
Used in conjunction with TextMemberPath, gets or sets a value indicating whether items in the view will trigger an update of the editable text part of the AutoSuggestBox when clicked.
public : PlatForm::Boolean UpdateTextOnSelect { get; set; }public bool UpdateTextOnSelect { get; set; }Public ReadWrite Property UpdateTextOnSelect As bool// This API is not available in Javascript.
<AutoSuggestBox UpdateTextOnSelect="bool"/>
- Value
- PlatForm::Boolean bool bool bool
A value indicating whether items in the view will trigger an update of the editable text part of the AutoSuggestBox when clicked.
UpdateTextOnSelectProperty UpdateTextOnSelectProperty UpdateTextOnSelectProperty UpdateTextOnSelectProperty
Identifies the UpdateTextOnSelect dependency property.
public : static DependencyProperty UpdateTextOnSelectProperty { get; }public static DependencyProperty UpdateTextOnSelectProperty { get; }Public Static ReadOnly Property UpdateTextOnSelectProperty As DependencyProperty// This API is not available in Javascript.
Identifier for the UpdateTextOnSelect dependency property.
Events
QuerySubmitted QuerySubmitted QuerySubmitted QuerySubmitted
Occurs when the user submits a search query.
public : event TypedEventHandler QuerySubmitted<AutoSuggestBox, AutoSuggestBoxQuerySubmittedEventArgs>public event TypedEventHandler QuerySubmitted<AutoSuggestBox, AutoSuggestBoxQuerySubmittedEventArgs>Public Event QuerySubmitted<AutoSuggestBox, AutoSuggestBoxQuerySubmittedEventArgs>// This API is not available in Javascript.
<AutoSuggestBox QuerySubmitted="eventhandler"/>
Remarks
SuggestionChosen SuggestionChosen SuggestionChosen SuggestionChosen
Raised before the text content of the editable control component is updated.
public : event TypedEventHandler SuggestionChosen<AutoSuggestBox, AutoSuggestBoxSuggestionChosenEventArgs>public event TypedEventHandler SuggestionChosen<AutoSuggestBox, AutoSuggestBoxSuggestionChosenEventArgs>Public Event SuggestionChosen<AutoSuggestBox, AutoSuggestBoxSuggestionChosenEventArgs>// This API is not available in Javascript.
<AutoSuggestBox SuggestionChosen="eventhandler"/>
Remarks
Respond to this event when you would like to display information in the editable part of the text control beyond what is provided by TextMemberPath.
TextChanged TextChanged TextChanged TextChanged
Raised after the text content of the editable control component is updated.
public : event TypedEventHandler TextChanged<AutoSuggestBox, AutoSuggestBoxTextChangedEventArgs>public event TypedEventHandler TextChanged<AutoSuggestBox, AutoSuggestBoxTextChangedEventArgs>Public Event TextChanged<AutoSuggestBox, AutoSuggestBoxTextChangedEventArgs>// This API is not available in Javascript.
<AutoSuggestBox TextChanged="eventhandler"/>
Remarks
Using the AutoSuggestBoxTextChangedEventArgs data for this event, your app can differentiate between changes from a user typing in the TextBox versus an item being selected from the drop-down suggestion list.