I'm trying to do a search filter on my program. I've already seen this post to understand how to start (Filtering ICollectionView binded to ItemsControl), but I have some errors that I can't fix.
public class SchedulingPageVm : PageViewModel
{
private readonly NcManager _ncManager;
private readonly Scheduler _scheduler;
private String _ncResearch;
public ICollection<Nc> Ncs => _ncManager.Ncs;
public string _NcResearch
{
get { return _ncResearch; }
set
{
_ncResearch = value;
OnPropertyChanged("NcList");
}
}
private RelayCommand _search;
public RelayCommand Search => _search ??= new RelayCommand(_Search);
public SchedulingPageVm(ICollection<JobDocument> ElencoNc)
{
InitializeComponent();
ElencoNc = (ICollection<JobDocument>)_ncManager.Ncs;
NcView.Filter = new Predicate<object>(object => _Search(object as _ncResearch));
this.DataContext = _ncManager.Ncs;
}
private bool _Search(JobDocument elencoNc)
{
return _ncResearch == null
|| elencoNc.Code.IndexOf(_ncResearch, StringComparison.OrdinalIgnoreCase) != -1
|| elencoNc.FileName.IndexOf(_ncResearch, StringComparison.OrdinalIgnoreCase) != -1
|| elencoNc.FilePath.IndexOf(_ncResearch, StringComparison.OrdinalIgnoreCase) != -1;
}
public CollectionView NcView
{
get { return (CollectionView)CollectionViewSource.GetDefaultView(_ncManager.Ncs); }
}
public ObservableCollection<Nc> DataContext { get; }
Errors:
public RelayCommand Search => _search ??= new RelayCommand(_Search);
Argument 1: cannot convert from 'method group' to 'System.Action'
NcView.Filter = new Predicate<object>(object,_Search(object as _ncResearch));
The type or namespace name '_ncReasearch' could not be found (you are missing a using directive or an assembly reference)* *Error invalid expression term 'object'