public class SortingFilteringViewModel : INotifyPropertyChanged
{
private string searchText = null;
public ObservableCollection<TaskInfo> Items { get; set; }
public Command<object> FilterCommand { get; set; }
public DataSource FilterDataSource { get; set; }
public SortingFilteringViewModel()
{
FilterCommand = new Command<object>(OnTextChanged);
FilterDataSource = new DataSource();
FilterDataSource.Source = Items;
AddItemDetails();
}
private void OnTextChanged(object obj)
{
searchText = obj as string;
if (FilterDataSource != null)
{
FilterDataSource.Filter = FilterContacts;
FilterDataSource.RefreshFilter();
}
}
private bool FilterContacts(object obj)
{
var taskInfo = obj as TaskInfo;
return (taskInfo.Title.ToLower().Contains(searchText.ToLower())
|| taskInfo.Description.ToLower().Contains(searchText.ToLower()));
}
} |
<sync:SfListView x:Name="listView"
ItemsSource="{Binding Items}"
DataSource="{Binding FilterDataSource}"
Grid.Row="1"
SelectionMode="None"
ItemSpacing="0,5,0,5"
BackgroundColor="#F0F0F0"
ItemSize="120"> |