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 AutoCompleteBox
class.
public AutoCompleteBox()
Properties
CanAutoSelectFirstItem
Gets or sets 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; otherwisefalse
. The default value istrue
.
CanSelectAllOnUpdate
Gets or sets 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; otherwisefalse
. The default value istrue
.
CharacterCasing
Gets or sets how characters are cased when they are manually entered into the text box.
public CharacterCasing CharacterCasing { get; set; }
Property Value
- CharacterCasing:
One of the
CharacterCasing
values that specifies how manually entered characters are cased. The default value isNormal
.
ClearCommand
Gets the ICommand that clears the text value.
public ICommand ClearCommand { get; }
Property Value
DataFilter
Gets or sets the IDataFilter to use for matching suggested items.
public IDataFilter DataFilter { get; set; }
Property Value
- IDataFilter:
The IDataFilter to use for matching suggested items.
DisplayMemberPath
Gets or sets the name of the property that provides each item's text within the suggestion list.
public string DisplayMemberPath { get; set; }
Property Value
- string:
The name of the property that provides each item's text within the suggestion list.
FilterText
Gets the text against which suggested items should be filtered.
protected virtual string FilterText { get; }
Property Value
- string:
The text against which suggested items should be filtered.
Remarks
The default implementation of this property returns the Text property value.
FilteredItemsSource
Gets the filtered collection of suggested items to display in the suggestion list.
public IEnumerable FilteredItemsSource { get; }
Property Value
- IEnumerable:
The filtered collection of suggested items to display in the suggestion list.
HasClearButton
Gets or sets a value indicating 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; otherwisefalse
. The default value isfalse
.
Remarks
When the InputMode is ComboBox
, the clear button will only be displayed if the control is focused.
HasItems
Gets 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
. The default value isfalse
.
HasPopupButton
Gets or sets a value indicating whether the control has a popup button.
public bool HasPopupButton { get; set; }
Property Value
- bool:
true
if the control has a popup button; otherwisefalse
. The default value istrue
.
InputMode
Gets or sets the input mode.
public AutoCompleteBoxInputMode InputMode { get; set; }
Property Value
- AutoCompleteBoxInputMode:
An AutoCompleteBoxInputMode that indicates the input mode. The default value is
Search
.
IsClearButtonVisible
Gets whether the clear button is visible.
public bool IsClearButtonVisible { get; }
Property Value
- bool:
true
if the clear button is visible; otherwisefalse
. The default value isfalse
.
Remarks
The HasClearButton property and other state-related info determines whether the clear button is visible.
IsNonDefaultUsageContext
Gets 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
. The default value isfalse
.
IsPopupButtonVisible
Gets whether the toggle popup button is visible.
public bool IsPopupButtonVisible { get; }
Property Value
- bool:
true
if the toggle popup button is visible; otherwisefalse
. The default value isfalse
.
Remarks
The HasPopupButton property determines whether the toggle popup button is visible.
IsPopupOpen
Gets or sets whether the popup is open.
public bool IsPopupOpen { get; set; }
Property Value
- bool:
true
if the popup is open; otherwise,false
. The default value isfalse
.
IsPopupOpenedOnFocus
Gets or sets 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 isfalse
.
IsReadOnly
Gets or sets a value indicating whether the control is read-only.
public bool IsReadOnly { get; set; }
Property Value
- bool:
true
if the control is read-only; otherwisefalse
. The default value isfalse
.
ItemContainerStyle
Gets or sets the Style that is applied to the container generated for each item.
public Style ItemContainerStyle { get; set; }
Property Value
ItemContainerStyleSelector
Gets or sets 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
Gets or sets the DataTemplate used to render items in the suggestion list.
public DataTemplate ItemTemplate { get; set; }
Property Value
- DataTemplate:
The DataTemplate used to render items in the suggestion list.
ItemTemplateSelector
Gets or sets the DataTemplateSelector used to render items in the suggestion list.
public DataTemplateSelector ItemTemplateSelector { get; set; }
Property Value
- DataTemplateSelector:
The DataTemplateSelector used to render items in the suggestion list.
ItemsSource
Gets or sets the collection of suggestion items that is filtered based on the user-entered text.
public IEnumerable ItemsSource { get; set; }
Property Value
- IEnumerable:
The collection of suggested items that is filtered based on the user-entered text.
MaxPopupHeight
Gets or sets the maximum height of the popup.
public double MaxPopupHeight { get; set; }
Property Value
- double:
The maximum height of the popup. The default value is
500
.
MinCharacterCountToOpenPopup
Gets or sets the minimum number of characters that need to be typed to open the popup.
public int MinCharacterCountToOpenPopup { get; set; }
Property Value
- int:
The minimum number of characters that need to be typed to open the popup. The default value is
1
.
NoItemsContent
Gets or sets the content to display when the popup is open but there are no suggested items.
public object NoItemsContent { get; set; }
Property Value
- object:
The content to display when the popup is open but there are no suggested items.
NoItemsContentTemplate
Gets or sets the DataTemplate to display when the popup is open but there are no suggested items.
public DataTemplate NoItemsContentTemplate { get; set; }
Property Value
- DataTemplate:
The DataTemplate to display when the popup is open but there are no suggested items.
PlaceholderText
Gets or sets the placeholder text to be displayed in the control.
public string PlaceholderText { get; set; }
Property Value
- string:
The placeholder text to be displayed in the control.
PopupHeader
Gets or sets the header content in the suggestion list popup.
public object PopupHeader { get; set; }
Property Value
- object:
The header content in the suggestion list popup.
PopupHeaderTemplate
Gets or sets the DataTemplate used to render the header in the suggestion list popup.
public DataTemplate PopupHeaderTemplate { get; set; }
Property Value
- DataTemplate:
The DataTemplate used to render the header in the suggestion list popup.
PopupHeaderTemplateSelector
Gets or sets the DataTemplateSelector used to render the header in the suggestion list popup.
public DataTemplateSelector PopupHeaderTemplateSelector { get; set; }
Property Value
- DataTemplateSelector:
The DataTemplateSelector used to render the header in the suggestion list popup.
SelectedItem
Gets or sets the selected suggested item.
Text
Gets or sets the text being edited in the control.
TextAlignment
Gets or sets the text alignment of the text editing area.
public TextAlignment TextAlignment { get; set; }
Property Value
- TextAlignment:
The text alignment of the text editing area. The default value is
TextAlignment.Left
.
TextMemberPath
Gets or sets the name of the property that provides each item's text.
public string TextMemberPath { get; set; }
Property Value
- string:
The name of the property that provides each item's text.
UsageContext
Gets or sets the usage context of the control, which may alter its appearance.
public ControlUsageContext UsageContext { get; set; }
Property Value
- ControlUsageContext:
The usage context of the control, which may alter its appearance. The default value is
ControlUsageContext.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()
Invoked whenever application code or internal processes call ApplyTemplate
.
public override void OnApplyTemplate()
OnCreateAutomationPeer()
Returns an AutomationPeer object for this control instance.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer:
An AutomationPeer instance.
OnGotFocus(RoutedEventArgs)
Occurs when the control gains focus.
protected override void OnGotFocus(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | The RoutedEventArgs that contains the event data. |
OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs)
Reports that the IsKeyboardFocusWithin
property changed.
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | DependencyPropertyChangedEventArgs | A |
OnLostMouseCapture(MouseEventArgs)
Occurs when mouse capture is lost.
protected override void OnLostMouseCapture(MouseEventArgs e)
Parameter | Type | Description |
---|---|---|
e | MouseEventArgs | The MouseEventArgs that contains the event data. |
OnMouseWheel(MouseWheelEventArgs)
Occurs when the mouse wheel is rotated.
protected override void OnMouseWheel(MouseWheelEventArgs e)
Parameter | Type | Description |
---|---|---|
e | MouseWheelEventArgs | The MouseWheelEventArgs that contains the event data. |
OnPreviewMouseDown(MouseButtonEventArgs)
Occurs before a mouse button is pressed over the control.
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
Parameter | Type | Description |
---|---|---|
e | MouseButtonEventArgs | The MouseButtonEventArgs that contains the event data. |
OnSelectedItemChanged(AutoCompleteBoxEventArgs)
Occurs when the SelectedItem property has changed.
protected virtual void OnSelectedItemChanged(AutoCompleteBoxEventArgs e)
Parameter | Type | Description |
---|---|---|
e | AutoCompleteBoxEventArgs | The |
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 |
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 |
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 |
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
Identifies the CanAutoSelectFirstItem dependency property. This field is read-only.
public static readonly DependencyProperty CanAutoSelectFirstItemProperty
CanSelectAllOnUpdateProperty
Identifies the CanSelectAllOnUpdate dependency property. This field is read-only.
public static readonly DependencyProperty CanSelectAllOnUpdateProperty
CharacterCasingProperty
Identifies the CharacterCasing dependency property. This field is read-only.
public static readonly DependencyProperty CharacterCasingProperty
DataFilterProperty
Identifies the DataFilter dependency property. This field is read-only.
public static readonly DependencyProperty DataFilterProperty
DisplayMemberPathProperty
Identifies the DisplayMemberPath dependency property. This field is read-only.
public static readonly DependencyProperty DisplayMemberPathProperty
HasClearButtonProperty
Identifies the HasClearButton dependency property. This field is read-only.
public static readonly DependencyProperty HasClearButtonProperty
HasItemsProperty
Identifies the HasItems dependency property. This field is read-only.
public static readonly DependencyProperty HasItemsProperty
HasPopupButtonProperty
Identifies the HasPopupButton dependency property. This field is read-only.
public static readonly DependencyProperty HasPopupButtonProperty
InputModeProperty
Identifies the InputMode dependency property. This field is read-only.
public static readonly DependencyProperty InputModeProperty
IsClearButtonVisibleProperty
Identifies the IsClearButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsClearButtonVisibleProperty
IsNonDefaultUsageContextProperty
Identifies the IsNonDefaultUsageContext dependency property. This field is read-only.
public static readonly DependencyProperty IsNonDefaultUsageContextProperty
IsPopupButtonVisibleProperty
Identifies the IsPopupButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsPopupButtonVisibleProperty
IsPopupOpenProperty
Identifies the IsPopupOpen dependency property. This field is read-only.
public static readonly DependencyProperty IsPopupOpenProperty
IsPopupOpenedOnFocusProperty
Identifies the IsPopupOpenedOnFocus dependency property. This field is read-only.
public static readonly DependencyProperty IsPopupOpenedOnFocusProperty
IsReadOnlyProperty
Identifies the IsReadOnly dependency property. This field is read-only.
public static readonly DependencyProperty IsReadOnlyProperty
ItemContainerStyleProperty
Identifies the ItemContainerStyle dependency property. This field is read-only.
public static readonly DependencyProperty ItemContainerStyleProperty
ItemContainerStyleSelectorProperty
Identifies the ItemContainerStyleSelector dependency property. This field is read-only.
public static readonly DependencyProperty ItemContainerStyleSelectorProperty
ItemTemplateProperty
Identifies the ItemTemplate dependency property. This field is read-only.
public static readonly DependencyProperty ItemTemplateProperty
ItemTemplateSelectorProperty
Identifies the ItemTemplateSelector dependency property. This field is read-only.
public static readonly DependencyProperty ItemTemplateSelectorProperty
ItemsSourceProperty
Identifies the ItemsSource dependency property. This field is read-only.
public static readonly DependencyProperty ItemsSourceProperty
MaxPopupHeightProperty
Identifies the MaxPopupHeight dependency property. This field is read-only.
public static readonly DependencyProperty MaxPopupHeightProperty
MinCharacterCountToOpenPopupProperty
Identifies the MinCharacterCountToOpenPopup dependency property. This field is read-only.
public static readonly DependencyProperty MinCharacterCountToOpenPopupProperty
NoItemsContentProperty
Identifies the NoItemsContent dependency property. This field is read-only.
public static readonly DependencyProperty NoItemsContentProperty
NoItemsContentTemplateProperty
Identifies the NoItemsContentTemplate dependency property. This field is read-only.
public static readonly DependencyProperty NoItemsContentTemplateProperty
PlaceholderTextProperty
Identifies the PlaceholderText dependency property. This field is read-only.
public static readonly DependencyProperty PlaceholderTextProperty
PopupHeaderProperty
Identifies the PopupHeader dependency property. This field is read-only.
public static readonly DependencyProperty PopupHeaderProperty
PopupHeaderTemplateProperty
Identifies the PopupHeaderTemplate dependency property. This field is read-only.
public static readonly DependencyProperty PopupHeaderTemplateProperty
PopupHeaderTemplateSelectorProperty
Identifies the PopupHeaderTemplateSelector dependency property. This field is read-only.
public static readonly DependencyProperty PopupHeaderTemplateSelectorProperty
SelectedItemChangedEvent
Identifies the SelectedItemChanged routed event. This field is read-only.
public static readonly RoutedEvent SelectedItemChangedEvent
SelectedItemProperty
Identifies the SelectedItem dependency property. This field is read-only.
public static readonly DependencyProperty SelectedItemProperty
SubmittedEvent
Identifies the Submitted routed event. This field is read-only.
public static readonly RoutedEvent SubmittedEvent
SuggestionChosenEvent
Identifies the SuggestionChosen routed event. This field is read-only.
public static readonly RoutedEvent SuggestionChosenEvent
TextAlignmentProperty
Identifies the TextAlignment dependency property. This field is read-only.
public static readonly DependencyProperty TextAlignmentProperty
TextChangedEvent
Identifies the TextChanged routed event. This field is read-only.
public static readonly RoutedEvent TextChangedEvent
TextMemberPathProperty
Identifies the TextMemberPath dependency property. This field is read-only.
public static readonly DependencyProperty TextMemberPathProperty
TextProperty
Identifies the Text dependency property. This field is read-only.
public static readonly DependencyProperty TextProperty
UsageContextProperty
Identifies the UsageContext dependency property. This field is read-only.
public static readonly DependencyProperty UsageContextProperty