In This Article

AutoCompleteBox Class

Represents a text control that provides suggestions to end users as they type.

[TemplatePart(Name = "PART_Popup", Type = typeof(Popup))]
[TemplatePart(Name = "PART_Selector", Type = typeof(EmbeddedListBox))]
[TemplatePart(Name = "PART_TextBox", Type = typeof(EmbeddedTextBox))]
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualState(Name = "PointerOver", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Focused", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
public class AutoCompleteBox : Control
Inheritance:
object Visual UIElement FrameworkElement Control object

Constructors

AutoCompleteBox()

Initializes an instance of the class.

public AutoCompleteBox()

Properties

CanAutoSelectFirstItem

Indicates whether the first item in the suggestion list can be selected under certain conditions, such as when typing is occurring.

public bool CanAutoSelectFirstItem { get; set; }

Property Value

bool:

true if the first item in the suggestion list can be selected under certain conditions, such as when typing is occurring; otherwise false. The default value is true.

CanSelectAllOnUpdate

Indicates whether the entire text should be selected following a text update, like a suggestion being chosen.

public bool CanSelectAllOnUpdate { get; set; }

Property Value

bool:

true if the entire text should be selected following a text update, like a suggestion being chosen; otherwise false. The default value is true.

CharacterCasing

The casing used for characters when they are manually entered into the text box.

public CharacterCasing CharacterCasing { get; set; }

Property Value

CharacterCasing:

The default value is Normal.

ClearCommand

The ICommand that clears the text value.

public ICommand ClearCommand { get; }

Property Value

ICommand

DataFilter

The IDataFilter to use for matching suggested items.

public IDataFilter? DataFilter { get; set; }

Property Value

IDataFilter

DisplayMemberPath

The name of the property that provides each item's text within the suggestion list.

public string DisplayMemberPath { get; set; }

Property Value

string

FilterText

The text against which suggested items should be filtered.

protected virtual string FilterText { get; }

Property Value

string

Remarks

The default implementation of this property returns the Text property value.

FilteredItemsSource

The filtered collection of suggested items to display in the suggestion list.

public IEnumerable FilteredItemsSource { get; }

Property Value

IEnumerable

HasClearButton

Indicates whether the control has a clear button when there is text.

public bool HasClearButton { get; set; }

Property Value

bool:

true if the control has a clear button when there is text; otherwise false. The default value is false.

Remarks

When the InputMode is ComboBox, the clear button will only be displayed if the control is focused.

HasItems

Indicates whether there is at least one suggested item in the suggestion list.

public bool HasItems { get; }

Property Value

bool:

true if there is at least one suggested item in the suggestion list; otherwise, false.

HasPopupButton

Indicates whether the control has a popup button.

public bool HasPopupButton { get; set; }

Property Value

bool:

true if the control has a popup button; otherwise false. The default value is true.

InputMode

The input mode.

public AutoCompleteBoxInputMode InputMode { get; set; }

Property Value

AutoCompleteBoxInputMode:

The default value is Search.

IsClearButtonVisible

Indicates whether the clear button is visible.

public bool IsClearButtonVisible { get; }

Property Value

bool:

true if the clear button is visible; otherwise false.

Remarks

The HasClearButton property and other state-related info determines whether the clear button is visible.

IsNonDefaultUsageContext

Indicates whether a non-default UsageContext is currently in effect.

public bool IsNonDefaultUsageContext { get; }

Property Value

bool:

true if a non-default UsageContext is currently in effect; otherwise, false.

IsPopupButtonVisible

Indicates whether the toggle popup button is visible.

public bool IsPopupButtonVisible { get; }

Property Value

bool:

true if the toggle popup button is visible; otherwise false.

Remarks

The HasPopupButton property determines whether the toggle popup button is visible.

IsPopupOpen

Indicates whether the popup is open.

public bool IsPopupOpen { get; set; }

Property Value

bool:

true if the popup is open; otherwise, false. The default value is false.

IsPopupOpenedOnFocus

Indicates whether the popup automatically opens when the control gains focus.

public bool IsPopupOpenedOnFocus { get; set; }

Property Value

bool:

true if the popup automatically opens when the control gains focus; otherwise, false. The default value is false.

IsReadOnly

Indicates whether the control is read-only.

public bool IsReadOnly { get; set; }

Property Value

bool:

true if the control is read-only; otherwise false. The default value is false.

ItemContainerStyle

The Style that is applied to the container generated for each item.

public Style? ItemContainerStyle { get; set; }

Property Value

Style:

The default value is null.

ItemContainerStyleSelector

Custom style-selection logic for a style that can be applied to each generated container.

public StyleSelector? ItemContainerStyleSelector { get; set; }

Property Value

StyleSelector:

A StyleSelector object that contains logic that chooses the style to use as the ItemContainerStyle. The default value is null.

ItemTemplate

The DataTemplate used to render items in the suggestion list.

public DataTemplate? ItemTemplate { get; set; }

Property Value

DataTemplate

ItemTemplateSelector

The DataTemplateSelector used to render items in the suggestion list.

public DataTemplateSelector? ItemTemplateSelector { get; set; }

Property Value

DataTemplateSelector

ItemsSource

The collection of suggestion items that is filtered based on the user-entered text.

public IEnumerable? ItemsSource { get; set; }

Property Value

IEnumerable

MaxPopupHeight

The maximum height of the popup.

public double MaxPopupHeight { get; set; }

Property Value

double:

The default value is 500.

MinCharacterCountToOpenPopup

The minimum number of characters that need to be typed to open the popup.

public int MinCharacterCountToOpenPopup { get; set; }

Property Value

int:

The default value is 1.

NoItemsContent

The content to display when the popup is open but there are no suggested items.

public object? NoItemsContent { get; set; }

Property Value

object

NoItemsContentTemplate

The DataTemplate to display when the popup is open but there are no suggested items.

public DataTemplate? NoItemsContentTemplate { get; set; }

Property Value

DataTemplate

PlaceholderText

The placeholder text to be displayed in the control.

public string? PlaceholderText { get; set; }

Property Value

string

PopupHeader

The header content in the suggestion list popup.

public object? PopupHeader { get; set; }

Property Value

object

PopupHeaderTemplate

The DataTemplate used to render the header in the suggestion list popup.

public DataTemplate? PopupHeaderTemplate { get; set; }

Property Value

DataTemplate

PopupHeaderTemplateSelector

The DataTemplateSelector used to render the header in the suggestion list popup.

public DataTemplateSelector? PopupHeaderTemplateSelector { get; set; }

Property Value

DataTemplateSelector

SelectedItem

The selected suggested item.

public object? SelectedItem { get; set; }

Property Value

object

Text

The text being edited in the control.

public string Text { get; set; }

Property Value

string

TextAlignment

The text alignment of the text editing area.

public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment:

The default value is TextAlignment.Left.

TextMemberPath

The name of the property that provides each item's text.

public string TextMemberPath { get; set; }

Property Value

string

UsageContext

The usage context of the control, which may alter its appearance.

public ControlUsageContext UsageContext { get; set; }

Property Value

ControlUsageContext:

The default value is Default.

Methods

ConvertToString(object?)

Converts the specified suggested item to a string representation.

protected virtual string ConvertToString(object? itemToConvert)
Parameter Type Description
itemToConvert object

The suggested item to convert.

Returns

string:

The string representation of the specified suggested item.

OnApplyTemplate()

When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate().

public override void OnApplyTemplate()

OnCreateAutomationPeer()

Returns class-specific AutomationPeer implementations for the Windows Presentation Foundation (WPF) infrastructure.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer:

The type-specific AutomationPeer implementation.

OnGotFocus(RoutedEventArgs)

Invoked whenever an unhandled GotFocus event reaches this element in its route.

protected override void OnGotFocus(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

The RoutedEventArgs that contains the event data.

OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs)

Invoked just before the IsKeyboardFocusWithinChanged event is raised by this element. Implement this method to add class handling for this event.

protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
Parameter Type Description
e DependencyPropertyChangedEventArgs

A System.Windows.DependencyPropertyChangedEventArgs that contains the event data.

OnLostMouseCapture(MouseEventArgs)

Invoked when an unhandled System.Windows.Input.Mouse.LostMouseCapture attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

protected override void OnLostMouseCapture(MouseEventArgs e)
Parameter Type Description
e MouseEventArgs

The MouseEventArgs that contains event data.

OnMouseWheel(MouseWheelEventArgs)

Invoked when an unhandled System.Windows.Input.Mouse.MouseWheel attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

protected override void OnMouseWheel(MouseWheelEventArgs e)
Parameter Type Description
e MouseWheelEventArgs

The MouseWheelEventArgs that contains the event data.

OnPreviewMouseDown(MouseButtonEventArgs)

Invoked when an unhandled System.Windows.Input.Mouse.PreviewMouseDown attached routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
Parameter Type Description
e MouseButtonEventArgs

The MouseButtonEventArgs that contains the event data. The event data reports that one or more mouse buttons were pressed.

OnSelectedItemChanged(AutoCompleteBoxEventArgs)

Occurs when the SelectedItem property has changed.

protected virtual void OnSelectedItemChanged(AutoCompleteBoxEventArgs e)
Parameter Type Description
e AutoCompleteBoxEventArgs

The event data.

Remarks

This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

OnSubmitted(AutoCompleteBoxEventArgs)

Occurs when the end user submits a text entry, generally by pressing Enter.

protected virtual void OnSubmitted(AutoCompleteBoxEventArgs e)
Parameter Type Description
e AutoCompleteBoxEventArgs

The event data.

Remarks

This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

OnSuggestionChosen(AutoCompleteBoxEventArgs)

Occurs when a suggested item is chosen and needs to be converted to text.

protected virtual void OnSuggestionChosen(AutoCompleteBoxEventArgs e)
Parameter Type Description
e AutoCompleteBoxEventArgs

The event data.

Remarks

This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

OnTextChanged(AutoCompleteBoxEventArgs)

Occurs when the Text is changed.

protected virtual void OnTextChanged(AutoCompleteBoxEventArgs e)
Parameter Type Description
e AutoCompleteBoxEventArgs

The event data.

Remarks

This method has no default implementation. Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

SelectAll()

Selects all the contents of the text-editing control.

public void SelectAll()

Events

SelectedItemChanged

Occurs when the SelectedItem property has changed.

public event EventHandler<AutoCompleteBoxEventArgs> SelectedItemChanged

Event Type

EventHandler<AutoCompleteBoxEventArgs>

Submitted

Occurs when the end user submits a text entry, generally by pressing Enter.

public event EventHandler<AutoCompleteBoxEventArgs> Submitted

Event Type

EventHandler<AutoCompleteBoxEventArgs>

SuggestionChosen

Occurs when a suggested item is chosen and needs to be converted to text.

public event EventHandler<AutoCompleteBoxEventArgs> SuggestionChosen

Event Type

EventHandler<AutoCompleteBoxEventArgs>

TextChanged

Occurs when the Text is changed.

public event EventHandler<AutoCompleteBoxEventArgs> TextChanged

Event Type

EventHandler<AutoCompleteBoxEventArgs>

Fields

CanAutoSelectFirstItemProperty

Defines the CanAutoSelectFirstItem property.

public static readonly DependencyProperty CanAutoSelectFirstItemProperty

CanSelectAllOnUpdateProperty

Defines the CanSelectAllOnUpdate property.

public static readonly DependencyProperty CanSelectAllOnUpdateProperty

CharacterCasingProperty

Defines the CharacterCasing property.

public static readonly DependencyProperty CharacterCasingProperty

DataFilterProperty

Defines the DataFilter property.

public static readonly DependencyProperty DataFilterProperty

DisplayMemberPathProperty

Defines the DisplayMemberPath property.

public static readonly DependencyProperty DisplayMemberPathProperty

HasClearButtonProperty

Defines the HasClearButton property.

public static readonly DependencyProperty HasClearButtonProperty

HasItemsProperty

Defines the HasItems property.

public static readonly DependencyProperty HasItemsProperty

HasPopupButtonProperty

Defines the HasPopupButton property.

public static readonly DependencyProperty HasPopupButtonProperty

InputModeProperty

Defines the InputMode property.

public static readonly DependencyProperty InputModeProperty

IsClearButtonVisibleProperty

Defines the IsClearButtonVisible property.

public static readonly DependencyProperty IsClearButtonVisibleProperty

IsNonDefaultUsageContextProperty

Defines the IsNonDefaultUsageContext property.

public static readonly DependencyProperty IsNonDefaultUsageContextProperty

IsPopupButtonVisibleProperty

Defines the IsPopupButtonVisible property.

public static readonly DependencyProperty IsPopupButtonVisibleProperty

IsPopupOpenProperty

Defines the IsPopupOpen property.

public static readonly DependencyProperty IsPopupOpenProperty

IsPopupOpenedOnFocusProperty

Defines the IsPopupOpenedOnFocus property.

public static readonly DependencyProperty IsPopupOpenedOnFocusProperty

IsReadOnlyProperty

Defines the IsReadOnly property.

public static readonly DependencyProperty IsReadOnlyProperty

ItemContainerStyleProperty

Defines the ItemContainerStyle property.

public static readonly DependencyProperty ItemContainerStyleProperty

ItemContainerStyleSelectorProperty

Defines the ItemContainerStyleSelector property.

public static readonly DependencyProperty ItemContainerStyleSelectorProperty

ItemTemplateProperty

Defines the ItemTemplate property.

public static readonly DependencyProperty ItemTemplateProperty

ItemTemplateSelectorProperty

Defines the ItemTemplateSelector property.

public static readonly DependencyProperty ItemTemplateSelectorProperty

ItemsSourceProperty

Defines the ItemsSource property.

public static readonly DependencyProperty ItemsSourceProperty

MaxPopupHeightProperty

Defines the MaxPopupHeight property.

public static readonly DependencyProperty MaxPopupHeightProperty

MinCharacterCountToOpenPopupProperty

Defines the MinCharacterCountToOpenPopup property.

public static readonly DependencyProperty MinCharacterCountToOpenPopupProperty

NoItemsContentProperty

Defines the NoItemsContent property.

public static readonly DependencyProperty NoItemsContentProperty

NoItemsContentTemplateProperty

Defines the NoItemsContentTemplate property.

public static readonly DependencyProperty NoItemsContentTemplateProperty

PlaceholderTextProperty

Defines the PlaceholderText property.

public static readonly DependencyProperty PlaceholderTextProperty

PopupHeaderProperty

Defines the PopupHeader property.

public static readonly DependencyProperty PopupHeaderProperty

PopupHeaderTemplateProperty

Defines the PopupHeaderTemplate property.

public static readonly DependencyProperty PopupHeaderTemplateProperty

PopupHeaderTemplateSelectorProperty

Defines the PopupHeaderTemplateSelector property.

public static readonly DependencyProperty PopupHeaderTemplateSelectorProperty

SelectedItemChangedEvent

Defines the SelectedItemChanged event.

public static readonly RoutedEvent SelectedItemChangedEvent

SelectedItemProperty

Defines the SelectedItem property.

public static readonly DependencyProperty SelectedItemProperty

SubmittedEvent

Defines the Submitted event.

public static readonly RoutedEvent SubmittedEvent

SuggestionChosenEvent

Defines the SuggestionChosen event.

public static readonly RoutedEvent SuggestionChosenEvent

TextAlignmentProperty

Defines the TextAlignment property.

public static readonly DependencyProperty TextAlignmentProperty

TextChangedEvent

Defines the TextChanged event.

public static readonly RoutedEvent TextChangedEvent

TextMemberPathProperty

Defines the TextMemberPath property.

public static readonly DependencyProperty TextMemberPathProperty

TextProperty

Defines the Text property.

public static readonly DependencyProperty TextProperty

UsageContextProperty

Defines the UsageContext property.

public static readonly DependencyProperty UsageContextProperty

Extension Methods