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:
trueif the first item in the suggestion list can be selected under certain conditions, such as when typing is occurring; otherwisefalse. The default value istrue.
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:
trueif the entire text should be selected following a text update, like a suggestion being chosen; otherwisefalse. The default value istrue.
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.
DataFilter
The IDataFilter to use for matching suggested items.
DisplayMemberPath
The name of the property that provides each item's text within the suggestion list.
FilterText
The text against which suggested items should be filtered.
protected virtual string FilterText { get; }
Property Value
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.
HasClearButton
Indicates whether the control has a clear button when there is text.
public bool HasClearButton { get; set; }
Property Value
- bool:
trueif the control has a clear button when there is text; otherwisefalse. The default value isfalse.
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:
trueif 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:
trueif the control has a popup button; otherwisefalse. The default value istrue.
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:
trueif the clear button is visible; otherwisefalse.
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:
trueif 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:
trueif the toggle popup button is visible; otherwisefalse.
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:
trueif the popup is open; otherwise,false. The default value isfalse.
IsPopupOpenedOnFocus
Indicates whether the popup automatically opens when the control gains focus.
public bool IsPopupOpenedOnFocus { get; set; }
Property Value
- bool:
trueif the popup automatically opens when the control gains focus; otherwise,false. The default value isfalse.
IsReadOnly
Indicates whether the control is read-only.
public bool IsReadOnly { get; set; }
Property Value
- bool:
trueif the control is read-only; otherwisefalse. The default value isfalse.
ItemContainerStyle
The Style that is applied to the container generated for each item.
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.
ItemTemplateSelector
The DataTemplateSelector used to render items in the suggestion list.
ItemsSource
The collection of suggestion items that is filtered based on the user-entered text.
MaxPopupHeight
The maximum height of the popup.
MinCharacterCountToOpenPopup
The minimum number of characters that need to be typed to open the popup.
NoItemsContent
The content to display when the popup is open but there are no suggested items.
NoItemsContentTemplate
The DataTemplate to display when the popup is open but there are no suggested items.
PlaceholderText
The placeholder text to be displayed in the control.
PopupHeader
The header content in the suggestion list popup.
PopupHeaderTemplate
The DataTemplate used to render the header in the suggestion list popup.
PopupHeaderTemplateSelector
The DataTemplateSelector used to render the header in the suggestion list popup.
public DataTemplateSelector? PopupHeaderTemplateSelector { get; set; }
Property Value
SelectedItem
The selected suggested item.
Text
The text being edited in the control.
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.
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
Submitted
Occurs when the end user submits a text entry, generally by pressing Enter.
public event EventHandler<AutoCompleteBoxEventArgs> Submitted
Event Type
SuggestionChosen
Occurs when a suggested item is chosen and needs to be converted to text.
public event EventHandler<AutoCompleteBoxEventArgs> SuggestionChosen
Event Type
TextChanged
Occurs when the Text is changed.
public event EventHandler<AutoCompleteBoxEventArgs> TextChanged
Event Type
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