No Results Found in .NET MAUI Autocomplete (SfAutocomplete)
2 May 20253 minutes to read
When the entered item is not in the suggestion list, SfAutocomplete displays a text indicating there is no search results found. We can set the desire text to be displayed for indicating no results found with the NoResultsFoundText and NoResultsFoundTemplate properties.
NoResultsFoundText
We can customize the desire text to be displayed for indicating no results found by using the NoResultsFoundText property.
<editors:SfAutocomplete x:Name="autocomplete"
NoResultsFoundText="Not Found"
ItemsSource="{Binding SocialMedias}"
TextMemberPath="Name"
DisplayMemberPath="Name"/>
SfAutocomplete autocomplete = new SfAutocomplete()
{
NoResultsFoundText = "Not Found",
DisplayMemberPath = "Name",
TextMemberPath = "Name",
ItemsSource = socialMediaViewModel.SocialMedias
};
NoResultsFoundTemplate
We can customize the appearance of the desire text to be displayed for indicating no results found by using the NoResultsFoundTemplate property.
<editors:SfAutocomplete x:Name="autocomplete"
ItemsSource="{Binding SocialMedias}"
TextMemberPath="Name"
DisplayMemberPath="Name" >
<editors:SfAutocomplete.NoResultsFoundTemplate>
<DataTemplate>
<Label Text="Not Found" FontSize="20" FontAttributes="Italic" TextColor="Red" Margin="70,10,0,0"/>
</DataTemplate>
</editors:SfAutocomplete.NoResultsFoundTemplate>
</editors:SfAutocomplete>
SfAutocomplete autocomplete = new SfAutocomplete()
{
ItemsSource = socialMediaViewModel.SocialMedias
TextMemberPath = "Name",
DisplayMemberPath = "Name",
NoResultsFoundTemplate = new DataTemplate(() =>
{
return new Label
{
Text = "Not Found",
FontSize = 20,
FontAttributes = FontAttributes.Italic,
TextColor = Colors.Red,
Margin = new Thickness(70, 10, 0, 0)
};
})
};
NOTE
By Default NoResultsFoundText is enabled we can restrict it by using NoResultsFoundText as Empty.