I created a sample Pet List with a Search View at the very top. The Search View would help user filter results of the List. The implementation works in IOS but I get an error in Android.
in IOS:
in Android:
Here is How I implemented it:
1. I created a view model with the SearchItem as one of the properties
public class PetsViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private IList _pets;
private IList originalList;
private int _current;
private string _searchTerm;
public string SearchTerm {
get => _searchTerm;
set
{
if (_searchTerm != value)
{
_searchTerm = value;
RaisePropertyChanged();
if (string.IsNullOrWhiteSpace(_searchTerm))
{// if search string is null List to original list
Pets = originalList;
}
else
{// show data that has filtered data
var data = Pets.Where(i => i.Name.Contains(_searchTerm));
Pets = (IList<Pet>)data;
}
}
}
}
in XAML I used binding with the SearchBar
SearchBar Placeholder="Name or Keyword" Text="{Binding SearchTerm, Mode=TwoWay}"