Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Complete using Xamarin Forms in C#

I am trying to create a AutoComplete Text Entry using Xamarin Forms. Can anybody help me in creating a custom renderer for the auto complete text field in C#. I am using MVVM concept.

like image 978
Nagashree Siddalingappa Avatar asked Jan 16 '15 12:01

Nagashree Siddalingappa


1 Answers

You can achieve it using the following components.

An Entry field with TextChanged Event. A ListView which to display the data set. As a first step you can create the Entry and ListView in a StackLayout with Vertical alignment. Set ItemSource of the ListView to your data set. Add the following code in your function for TextChanged event

void OnTextChanged(object sender, EventArgs args)
{
    Site_listView.ItemsSource = vm.SiteList.Where(x => x.siteName.ToLower().Contains(siteNameEntry.Text.ToString().ToLower())).ToList();

}

Site_listView, siteNameEntry are the x:Name of ListView and Entry respectively

You can use ItemSelected/ItemTapped events in the list view for selecting the item from the list and assigning it to the Entry. Also you can use Focused, UnFocused events also to set the visibility of the list.

like image 91
Nidhin Vijay Avatar answered Sep 21 '22 11:09

Nidhin Vijay