Auto​Suggest​Box Auto​Suggest​Box Auto​Suggest​Box 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
<AutoSuggestBox .../>
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Inherited Members

Inherited properties

Inherited events

Inherited methods

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.

An auto suggest box with an icon and suggestions 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&lt;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 keyDescription
AutoSuggestBoxSuggestionsListBackgroundBackground color of suggestion list
AutoSuggestBoxSuggestionsListBorderBrushBorder color of suggestion list
TextControlForegroundText color at rest
TextControlForegroundPointerOverText color on hover
TextControlForegroundFocusedText color when focused
TextControlForegroundDisabledText color when disabled
TextControlBackgroundBackground color at rest
TextControlBackgroundPointerOverBackground color on hover
TextControlBackgroundFocusedBackground color when focused
TextControlBackgroundDisabledBackground color when disabled
TextControlBorderBrushBorder color at rest
TextControlBorderBrushPointerOverBorder color on hover
TextControlBorderBrushFocusedBorder color when focused
TextControlBorderBrushDisabledBorder color when disabled
TextControlPlaceholderForegroundPlaceholder text color at rest
TextControlPlaceholderForegroundPointerOverPlaceholder text color on hover
TextControlPlaceholderForegroundFocusedPlaceholder text color when focused
TextControlPlaceholderForegroundDisabledPlaceholder text color when disabled
TextControlHeaderForegroundHeader text color at rest
TextControlHeaderForegroundDisabledHeader text color when disabled
TextControlSelectionHighlightColorHighlight color of selected text
TextControlButtonBackgroundBackground color of delete button at rest
TextControlButtonBackgroundPointerOverBackground color of delete button on hover
TextControlButtonBackgroundPressedBackground color of delete button when pressed
TextControlButtonBorderBrushBorder color of delete button at rest
TextControlButtonBorderBrushPointerOverBorder color of delete button on hover
TextControlButtonBorderBrushPressedBorder color of delete button when pressed
TextControlButtonForegroundForeground color of delete button at rest
TextControlButtonForegroundPointerOverForeground color of delete button on hover
TextControlButtonForegroundPressedForeground color of delete button when pressed

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.
    }
}

Constructors

AutoSuggestBox() AutoSuggestBox() AutoSuggestBox()

Initializes a new instance of the AutoSuggestBox class.

public AutoSuggestBox()public AutoSuggestBox()Public Sub New()
Attributes

Properties

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
<AutoSuggestBox AutoMaximizeSuggestionArea="bool"/>
Value
bool bool bool

A Boolean value that indicates if the suggestion area should be automatically maximized.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the AutoMaximizeSuggestionArea dependency property.

Attributes

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
<AutoSuggestBox Header="headerString"/>

Value
object object object

The header object for the text box portion of this control.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the Header dependency property.

Attributes

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
Value
bool bool bool

A Boolean value indicating whether the drop-down portion of the AutoSuggestBox is open.

Attributes

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

Identifies the IsSuggestionListOpen dependency property.

public static DependencyProperty IsSuggestionListOpenProperty { get; }public static DependencyProperty IsSuggestionListOpenProperty { get; }Public Static ReadOnly Property IsSuggestionListOpenProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

Identifier for the IsSuggestionListOpen dependency property.

Attributes

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
Value
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.

Attributes
Additional features and requirements
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

Identifies the LightDismissOverlayMode dependency property.

public static DependencyProperty LightDismissOverlayModeProperty { get; }public static DependencyProperty LightDismissOverlayModeProperty { get; }Public Static ReadOnly Property LightDismissOverlayModeProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the LightDismissOverlayMode dependency property.

Attributes
Additional features and requirements
Device family
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v3)

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
<AutoSuggestBox MaxSuggestionListHeight="double"/>
Value
double double double

The maximum height for the drop-down portion of the AutoSuggestBox control.

Attributes

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
Attributes

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
<AutoSuggestBox PlaceholderText="string"/>
Value
string string string

The placeholder text to be displayed in the control. The default is an empty string.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the PlaceholderText dependency property.

Attributes

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
<AutoSuggestBox QueryIcon="symbolName" .../>
Value
IconElement IconElement IconElement

The graphic content of the button that is clicked to initiate a query, if present; otherwise, null. The default is null.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the QueryIcon dependency property.

Attributes

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
Value
string string string

The text that is shown in the control.

Attributes

Remarks

This property is not typically set in XAML.

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
<AutoSuggestBox TextBoxStyle={StaticResource styleResourceKey}/>

Value
Style Style Style

The style of the auto-suggest text box.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

Identifier for the TextBoxStyle dependency property.

Attributes

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
<AutoSuggestBox TextMemberPath="propertyName"/>
Value
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.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

Identifier for the TextMemberPath dependency property.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the PlaceholderText dependency property.

Attributes

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
<AutoSuggestBox UpdateTextOnSelect="bool"/>
Value
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.

Attributes

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
Value
DependencyProperty DependencyProperty DependencyProperty

Identifier for the UpdateTextOnSelect dependency property.

Attributes

Events

QuerySubmitted QuerySubmitted QuerySubmitted

Occurs when the user submits a search query.

public event TypedEventHandler QuerySubmittedpublic event TypedEventHandler QuerySubmittedPublic Event QuerySubmitted
<AutoSuggestBox QuerySubmitted="eventhandler"/>
Attributes

Remarks

See AutoSuggestBoxQuerySubmittedEventArgs.

SuggestionChosen SuggestionChosen SuggestionChosen

Raised before the text content of the editable control component is updated.

public event TypedEventHandler SuggestionChosenpublic event TypedEventHandler SuggestionChosenPublic Event SuggestionChosen
<AutoSuggestBox SuggestionChosen="eventhandler"/>
Attributes

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

Raised after the text content of the editable control component is updated.

public event TypedEventHandler TextChangedpublic event TypedEventHandler TextChangedPublic Event TextChanged
<AutoSuggestBox TextChanged="eventhandler"/>
Attributes

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.

See Also