Autocomplete XLabs does not load data from the database

I'm using the control of xlabs, however it does not list the database information, in the debug I see that behind the data, but does not assemble the list.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
             x:Class="Livronautas.Pages.AddLivroPage" Title="Cadastrar um livro" BackgroundColor="#ffffff">

 <ContentPage.Resources>
        <ResourceDictionary>
            <!--  this isn't working yet  -->
            <DataTemplate x:Key="SugestionItemTemplate">
                <ViewCell Height="30">
                    <ViewCell.View>
                        <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                            <Label HorizontalOptions="Start" Text="{Binding Nome}" VerticalOptions="Center" />
                        </StackLayout>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>

 <controls:AutoCompleteView x:Name="MyAutoComplete" Placeholder="Título do livro" 
                                   SearchCommand="{Binding SearchCommand}"
                                   SelectedCommand="{Binding CellSelectedCommand}"
                                   SelectedItem="{Binding SelectedItem}"
                                   ShowSearchButton="False"
                                   Text="{Binding SearchTerm,Mode=TwoWay}"
                                   SuggestionBackgroundColor="White"
                                   SuggestionItemDataTemplate="{StaticResource SugestionItemTemplate}"
                                   Suggestions="{Binding Livros, Mode=TwoWay}" />
</ContentPage>

My Class

                public class AddlivroViewModel : BaseViewModel
                    {
                        private ObservableCollection<Livro> _livros;
                        private string _searchTerm;

                        private Command<string> _searchCommand;
                        private Command<Livro> _cellSelectedCommand;
                        private Livro _selectedItem;
                        public int Qtd = 100;
                        public int Page { get; set; }

                        public AddlivroViewModel() : base(DependencyService.Get<ILivronautasService>())
                        {
                            Page = 1;
                            Livros = new ObservableCollection<Livro>();
                            //UpdateViewModel(Page, Qtd);
                        }

                        public string SearchTerm
                        {
                            get => _searchTerm;
                            set =>SetProperty(ref _searchTerm, value);            
                        }

                        public async Task UpdateViewModel(int page, int take)
                        {
                            IsLoading = true;
                            var contents = await ApiService.GetLivros(page, take, SearchTerm);
                            Livros.Clear();
                            Debug.WriteLine(contents.Count);
                            foreach (var item in contents)
                                Livros.Add(item);

                            IsLoading = false;
                        }

                        async Task ExecuteAutocompleteSearchCommand(string param)
                        {
                            SearchTerm = param;
                            Debug.WriteLine(SearchTerm);
                            UpdateViewModel(Page, Qtd);
                        }

                        private async Task ExecuteSelectedSearchitemCommand(object itm)
                        {
                            Device.BeginInvokeOnMainThread(async () => {
                                await App.Current.MainPage.DisplayAlert("Message", "Selected Item :" + (itm as Livro).Nome, "Ok");

                            });
                        }

                        public ObservableCollection<Livro> Livros
                        {
                            get => _livros;
                            set => SetProperty(ref _livros, value);
                        }

                        public Command<Livro> CellSelectedCommand
                        {
                            get
                            {
                                return _cellSelectedCommand ?? (_cellSelectedCommand = new Command<Livro>(itm => ExecuteSelectedSearchitemCommand(itm)));
                            }
                        }

                        public Command<string> SearchCommand
                        {
                            get
                            {
                                return _searchCommand ?? (_searchCommand = new Command<string>(param => ExecuteAutocompleteSearchCommand(param)));
                            }
                        }

                        public Livro SelectedItem
                        {
                            get => _selectedItem;
                            set => SetProperty(ref _selectedItem, value);
                        }
                    }
Sign In or Register to comment.