First, create the Xamarin forms project and then update the all Nuget packages in your project.
Write this code in your MainPage.Xaml,
  1. <AbsoluteLayout>
  2. <Entry TextChanged="SearchBar_OnTextChanged" BackgroundColor="#f9f9f9" TextColor="#FF464859" FontSize="16" PlaceholderColor="#646b7a" x:Name="searchBar" Placeholder="Type here..." AbsoluteLayout.LayoutBounds="15,70,285,38" AbsoluteLayout.LayoutFlags="None"/>
  3. <ListView x:Name="countryListView" IsVisible="False" CachingStrategy="RecycleElement" BackgroundColor="White" ItemTapped="ListView_OnItemTapped" AbsoluteLayout.LayoutBounds="20,110,269,160" AbsoluteLayout.LayoutFlags="None">
  4. <ListView.ItemTemplate>
  5. <DataTemplate>
  6. <ViewCell>
  7. <Frame>
  8. <StackLayout BackgroundColor="White">
  9. <Label Text="{Binding .}" FontSize="16" TextColor="#FF464859"/>
  10. </StackLayout>
  11. </Frame>
  12. </ViewCell>
  13. </DataTemplate>
  14. </ListView.ItemTemplate>
  15. </ListView>
  16. </AbsoluteLayout>
And then write some code in MainPage.Xaml.cs class,
Initial declared ObservableCollection,
  1. ObservableCollection<string> data = new ObservableCollection<string>();
then add values in ObservableCollection through method,
  1. public async void ListOfStore() //List of Countries
  2. {
  3. try
  4. {
  5. data.Add("Afghanistan");
  6. data.Add("Austria");
  7. data.Add("Australia");
  8. data.Add("Azerbaijan");
  9. data.Add("Bahrain");
  10. data.Add("Bangladesh");
  11. data.Add("Belgium");
  12. data.Add("Botswana");
  13. data.Add("China");
  14. data.Add("Colombia");
  15. data.Add("Denmark");
  16. data.Add("Kmart");
  17. data.Add("Pakistan");
  18. }
  19. catch (Exception ex)
  20. {
  21. await DisplayAlert("", ""+ex, "Ok");
  22. }
  23. }
And now call this method ListOfStore() in Constructor,
  1. public MainPage()
  2. {
  3. InitializeComponent();
  4. ListOfStore();
  5. }
Now we create SearchBar_OnTextChanged method in MainPage.xaml.cs class,
  1. private void SearchBar_OnTextChanged(object sender, TextChangedEventArgs e)
  2. {
  3. countryListView.IsVisible = true;
  4. countryListView.BeginRefresh();
  5. try
  6. {
  7. var dataEmpty = data.Where(i => i.ToLower().Contains(e.NewTextValue.ToLower()));
  8. if (string.IsNullOrWhiteSpace(e.NewTextValue))
  9. countryListView.IsVisible = false;
  10. else if (dataEmpty.Max().Length == 0)
  11. countryListView.IsVisible = false;
  12. else
  13. countryListView.ItemsSource = data.Where(i => i.ToLower().Contains(e.NewTextValue.ToLower()));
  14. }
  15. catch (Exception ex)
  16. {
  17. countryListView.IsVisible = false;
  18. }
  19. countryListView.EndRefresh();
  20. }
Now we create ItemTapped method in MainPage.xaml.cs class,
  1. private void ListView_OnItemTapped(Object sender, ItemTappedEventArgs e)
  2. {
  3. //EmployeeListView.IsVisible = false;
  4. String listsd = e.Item as string;
  5. searchBar.Text = listsd;
  6. countryListView.IsVisible = false;
  7. ((ListView)sender).SelectedItem = null;
  8. }
Here is the full code,
  1. ObservableCollection<string> data = new ObservableCollection<string>();
  2. public MainPage()
  3. {
  4. InitializeComponent();
  5. ListOfStore();
  6. }
  7. public async void ListOfStore() //List of Countries
  8. {
  9. try
  10. {
  11. data.Add("Afghanistan");
  12. data.Add("Austria");
  13. data.Add("Australia");
  14. data.Add("Azerbaijan");
  15. data.Add("Bahrain");
  16. data.Add("Bangladesh");
  17. data.Add("Belgium");
  18. data.Add("Botswana");
  19. data.Add("China");
  20. data.Add("Colombia");
  21. data.Add("Denmark");
  22. data.Add("Kmart");
  23. data.Add("Pakistan");
  24. }
  25. catch (Exception ex)
  26. {
  27. await DisplayAlert("", ""+ex, "Ok");
  28. }
  29. }
  30. private void SearchBar_OnTextChanged(object sender, TextChangedEventArgs e)
  31. {
  32. countryListView.IsVisible = true;
  33. countryListView.BeginRefresh();
  34. try
  35. {
  36. var dataEmpty = data.Where(i => i.ToLower().Contains(e.NewTextValue.ToLower()));
  37. if (string.IsNullOrWhiteSpace(e.NewTextValue))
  38. countryListView.IsVisible = false;
  39. else if (dataEmpty.Max().Length == 0)
  40. countryListView.IsVisible = false;
  41. else
  42. countryListView.ItemsSource = data.Where(i => i.ToLower().Contains(e.NewTextValue.ToLower()));
  43. }
  44. catch (Exception ex)
  45. {
  46. countryListView.IsVisible = false;
  47. }
  48. countryListView.EndRefresh();
  49. }
  50. private void ListView_OnItemTapped(Object sender, ItemTappedEventArgs e)
  51. {
  52. //EmployeeListView.IsVisible = false;
  53. String listsd = e.Item as string;
  54. searchBar.Text = listsd;
  55. countryListView.IsVisible = false;
  56. ((ListView)sender).SelectedItem = null;
  57. }
  58. }
Here is a simple screenshot,
Autocomplete TextField With Suggestion Dropdown In Xamairn.Forms