Skip to content

AutoCompleteTextField

The AutoCompleteTextField extends TextField and adds autocomplete functionality with a popup list of suggestions.

AutoCompleteTextField provides intelligent text input with suggestions. It uses a debounced async provider to fetch suggestions as the user types.

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);
};

Maximum number of suggestions to display (default: 10).

autoCompleteField.MaxSuggestions = 5;

Delay in milliseconds before querying suggestions (default: 200).

autoCompleteField.DebounceDelay = 300;

Whether to show the popup above the text field (auto-calculated).

  • SuggestionBackgroundColor: Background color for suggestions
  • SuggestionForegroundColor: Text color for suggestions
  • SelectionHighlightColor: Color for selected suggestion

Manually shows suggestions.

autoCompleteField.ShowSuggestions(new List<string> { "Option 1", "Option 2" });

Hides the suggestions popup.

autoCompleteField.HideSuggestions();

Manually refreshes suggestions based on current text.

autoCompleteField.RefreshSuggestions();

Raised when a suggestion is selected.

autoCompleteField.SuggestionSelected += (suggestion) =>
{
Console.WriteLine($"Selected: {suggestion}");
};

Raised when the popup opens.

autoCompleteField.PopupOpened += () =>
{
// Popup is visible
};

Raised when the popup closes.

autoCompleteField.PopupClosed += () =>
{
// Popup is hidden
};

When popup is visible:

  • Up/Down Arrow: Navigate suggestions
  • Enter or Tab: Accept selected suggestion
  • Escape: Close popup
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}");
};