AutoCompleteTextField
The AutoCompleteTextField extends TextField and adds autocomplete functionality with a popup list of suggestions.
Overview
Section titled “Overview”AutoCompleteTextField provides intelligent text input with suggestions. It uses a debounced async provider to fetch suggestions as the user types.
Properties
Section titled “Properties”SuggestionsProvider (Func<string, Task<List<string>>>?)
Section titled “SuggestionsProvider (Func<string, Task<List<string>>>?)”An async function that provides suggestions based on the current text.
autoCompleteField.SuggestionsProvider = async (text) =>{ // Fetch suggestions asynchronously return await GetSuggestionsAsync(text);};MaxSuggestions (int)
Section titled “MaxSuggestions (int)”Maximum number of suggestions to display (default: 10).
autoCompleteField.MaxSuggestions = 5;DebounceDelay (int)
Section titled “DebounceDelay (int)”Delay in milliseconds before querying suggestions (default: 200).
autoCompleteField.DebounceDelay = 300;ShowPopupAbove (bool)
Section titled “ShowPopupAbove (bool)”Whether to show the popup above the text field (auto-calculated).
Color Properties
Section titled “Color Properties”SuggestionBackgroundColor: Background color for suggestionsSuggestionForegroundColor: Text color for suggestionsSelectionHighlightColor: Color for selected suggestion
Methods
Section titled “Methods”ShowSuggestions(List<string> suggestions)
Section titled “ShowSuggestions(List<string> suggestions)”Manually shows suggestions.
autoCompleteField.ShowSuggestions(new List<string> { "Option 1", "Option 2" });HideSuggestions()
Section titled “HideSuggestions()”Hides the suggestions popup.
autoCompleteField.HideSuggestions();RefreshSuggestions()
Section titled “RefreshSuggestions()”Manually refreshes suggestions based on current text.
autoCompleteField.RefreshSuggestions();Events
Section titled “Events”SuggestionSelected
Section titled “SuggestionSelected”Raised when a suggestion is selected.
autoCompleteField.SuggestionSelected += (suggestion) =>{ Console.WriteLine($"Selected: {suggestion}");};PopupOpened
Section titled “PopupOpened”Raised when the popup opens.
autoCompleteField.PopupOpened += () =>{ // Popup is visible};PopupClosed
Section titled “PopupClosed”Raised when the popup closes.
autoCompleteField.PopupClosed += () =>{ // Popup is hidden};Keyboard Navigation
Section titled “Keyboard Navigation”When popup is visible:
- Up/Down Arrow: Navigate suggestions
- Enter or Tab: Accept selected suggestion
- Escape: Close popup
Usage Example
Section titled “Usage Example”var autoComplete = new AutoCompleteTextField("Search..."){ X = 10, Y = 5, Width = 40, Height = 1};
autoComplete.SuggestionsProvider = async (text) =>{ if (string.IsNullOrWhiteSpace(text)) return new List<string>();
// Simulate async search await Task.Delay(100); return new List<string> { $"{text} result 1", $"{text} result 2", $"{text} result 3" };};
autoComplete.SuggestionSelected += (suggestion) =>{ Console.WriteLine($"Selected: {suggestion}");};Related Widgets
Section titled “Related Widgets”- TextField - Base text field class
- ListBox - Used internally for suggestions
- Base Widget - Base class documentation