Skip to content

Instantly share code, notes, and snippets.

@adityadeshpande
Created January 14, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityadeshpande/9884db9c58e8043c69c9dd4744089d2a to your computer and use it in GitHub Desktop.
Save adityadeshpande/9884db9c58e8043c69c9dd4744089d2a to your computer and use it in GitHub Desktop.
#region Fields
private ObservableCollection<object> _Items;
private ObservableCollection<object> _ItemsFiltered;
private ObservableCollection<object> _ItemsUnfiltered;
private string _searchText;
#endregion
#region Properties
public string SearchText
{
get { return _searchText; }
set
{
_searchText = value;
OnPropertyChanged("SearchText");
}
}
public ObservableCollection<object> Items
{
get { return _Items; }
set
{
_Items = value;
OnPropertyChanged("Items");
}
}
#endregion
#region Commands
public ICommand SearchCommand { get; private set; }
#endregion
#region Constructor
public ItemsViewModel()
{
Items = new ObservableCollection<object>();
GetItems();
SearchCommand = new Command(PerformSearch);
}
#endregion
#region Methods
public void PerformSearch()
{
if (string.IsNullOrWhiteSpace(this._searchText))
Items = _ItemsUnfiltered;
else
{
_ItemsFiltered = new ObservableCollection<object>(_ItemsUnfiltered.Where(i =>
(i is ItemObj && (((ItemObj)i).ItemObjName.ToLower().Contains(_searchText.ToLower())));
Items = _ItemsFiltered;
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment