Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searchbar xamarin forms

I a novice in Xamarin and C#

T want to add a dynamic searchbar (mean without pushing the search button) in my content view in order to search in my sqlite database.

I cannot figure out why it not working:

I have been trying to do the same things like in this tuto but with database but the list cannot display because the app is stopped

Here is my method in the database:

//SELECT   words
    public List<MyWords> SelectWords(string keyword)
    {

        var myword = (from word in conn.Table<MyWords>()
                      where word.Word1.ToLower().Contains(keyword.ToLower()) || word.Word2.ToLower().Contains(keyword.ToLower())
                      select word);

        return myword.ToList();


    }

Here is my method in the class of my contact page:

//search on the list view
        private void SearcMyWords(object sender, EventArgs e)
        {
           // var keyword = SearchWords.Text;

            var words = mywordsdatabase.SelectWords("car");

              listWordsView.ItemsSource = words;


        }

Here is my xaml page :

<SearchBar x:Name="SearchWords"
                       TextChanged=""/>

Thanks in advance.

like image 429
hugo Avatar asked Jul 16 '26 15:07

hugo


1 Answers

You forgot to implement the actual handler for the TextChanged property. Change your XAML like this:

<SearchBar x:Name="SearchWords" TextChanged="Handle_TextChanged"/>

And add a method in your code-behind, which will probably look something like this:

private void Handle_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e)
{
    SelectWords(e.NewTextValue);
}
like image 147
Gerald Versluis Avatar answered Jul 18 '26 03:07

Gerald Versluis