Fix Search filter C# WPF

Argument 1: cannot convert from ‘method group’ to ‘System.Action’

The RelayCommand expects a method signature like this.

void _Search(object obj)

Your _Search method does not match. You can either introduce a lambda to cast the object:

public RelayCommand Search => _search ??= new RelayCommand(obj => _Search((JobDocument)obj));

Or you can change the signature of the _Search method and cast the object in it, but I guess you need this method to return a bool for the filter, so you cannot do this.

private bool _Search(object obj)
   var elencoNc = (JobDocument) obj;
   // ...other code.

However, the main question here is why you create a command for this in the first place. The command does not return anything and your _Search method is a predicate, so it does not change any state. The invocation of the command does not do anything except waste CPU time.

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’

You are creating the Predicate<object> wrong. A predicate of that type gets an object instance as parameter and returns a bool as result of its check. On the left side of the as operator needs to be an instance and on the right side the type to cast to, here JobParameter.

NcView.Filter = new Predicate<object>(obj => _Search(obj as JobDocument));

You could even cast the obj directly like (JobDocument) obj and assign the Filter directly.

NcView.Filter = obj => _Search((JobParameter) obj);

Read more on the as operator in the documentation: as operator

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top