Created
January 14, 2018 06:21
-
-
Save adityadeshpande/9884db9c58e8043c69c9dd4744089d2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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