I tried to make custom Autocomplete as suggested in following question:
Xamarin.Forms Autocomplete CrossPlatform
it is working properly but there is some issue with UI.
when we type in textbox at that time listview
visible for selection but the control below the listview
is moves bottom of the screen. If i use grid for that then listview
not displaying properly.
Xaml
code is as bellow:
<StackLayout VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Orientation="Vertical"
Spacing="15">
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Entry x:Name="aaa" Grid.Row="0" Grid.Column="0"></Entry>
<ListView x:Name="Equipment_listView" ItemsSource="{Binding SiteListViewSource}" IsVisible="false" Grid.Row="1" Grid.Column="0">
<ListView.GroupHeaderTemplate>
<DataTemplate>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="5,0,0,0" Orientation="Horizontal">
<Label Text="{Binding Name}" YAlign="Center" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Entry x:Name="aa" Grid.Row="2" Grid.Column="0"></Entry>
</Grid>
</StackLayout>
.cs file code is as bellow:
public pg1()
{
InitializeComponent();
List<Person> people = new List<Person>
{
new Person("Abigail", new DateTime(1975, 1, 15), Color.Aqua,"images.png"),
new Person("Bob", new DateTime(1976, 2, 20), Color.Black,"images.png"),
new Person("Yvonne", new DateTime(1987, 1, 10), Color.Purple,"images.png"),
new Person("Zachary", new DateTime(1988, 2, 5), Color.Red,"images.png")
};
Equipment_listView.ItemsSource = people;
aaa.TextChanged += MyAutoComplete_TextChanged;
Equipment_listView.ItemTapped += (sender, e) =>
{
Person item = (Person)e.Item;
aaa.Text = item.Name;
Equipment_listView.IsVisible = false;
};
}
void MyAutoComplete_TextChanged(object sender, TextChangedEventArgs e)
{
List<Person> people = new List<Person>
{
new Person("Abigail", new DateTime(1975, 1, 15), Color.Aqua,"images.png"),
new Person("Bob", new DateTime(1976, 2, 20), Color.Black,"images.png"),
new Person("Yvonne", new DateTime(1987, 1, 10), Color.Purple,"images.png"),
new Person("Zachary", new DateTime(1988, 2, 5), Color.Red,"images.png"),
};
Equipment_listView.ItemsSource = people.Where(x => x.Name.ToLower().Contains(aaa.Text.ToString().ToLower())).ToList();
Equipment_listView.IsVisible = true;
}
please help me how to set i autocomplete properly or suggest me if any other way to implement Autocomplete with Xamarin forms
When i use grid, It is shows like this: GridImage
And When i do not use grid, It is shows like this: WithoutGridImage