ViewModel.cs
private bool FilterContacts(object obj)
{
if (searchBar == null || searchBar.Text == null)
return true;
var taskInfo = obj as TaskInfo;
return (taskInfo.Title.ToLower().Contains(searchBar.Text.ToLower())
|| taskInfo.Description.ToLower().Contains(searchBar.Text.ToLower())); }
|
private void OnTextChanged(object obj)
{
var grid = (obj as Grid);
searchBar = grid.Children[1] as SearchBar;
var listview = grid.Children[2] as SfListView;
if (listview!=null && listview.DataSource != null)
{
listview.DataSource.Filter = FilterContacts;
listview.DataSource.RefreshFilter();
}
listview.RefreshView();
}
private bool FilterContacts(object obj)
{
if (searchBar == null || searchBar.Text == null)
return true;
var taskInfo = obj as TaskInfo;
return (taskInfo.Title.ToLower().Contains(searchBar.Text.ToLower())
|| taskInfo.Description.ToLower().Contains(searchBar.Text.ToLower()));
}
|
listView.DataSource.GroupDescriptors.Add(new GroupDescriptor()
{
PropertyName = "Tag",
KeySelector = (object obj1) =>
{
var item = (obj1 as TaskInfo);
return item.Tag[0].ToString();
}
});
|
ViewModel.cs
private void OnTextChanged(object obj)
{
var grid = (obj as Grid);
searchBar = grid.Children[1] as SearchBar;
var listview = grid.Children[2] as SfListView;
if (listview != null && listview.DataSource != null)
{
listview.DataSource.Filter = FilterContacts;
listview.DataSource.RefreshFilter();
}
listview.RefreshView();
}
private bool FilterContacts(object obj)
{
bool isFiltered=false;
if (searchBar == null || searchBar.Text == null)
return true;
var taskInfo = obj as TaskInfo; //Codes for customize filter based on 2 keys
string str = searchBar.Text;
char[] separator = { ',', ' ' };
String[] strlist = str.Split(separator);
foreach (String s in strlist)
{
if( (taskInfo.Title.ToLower().Contains(s) || taskInfo.Tag.ToLower().Contains(s)))
{
isFiltered = true;
}
}
return isFiltered;
}
|