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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With