The action :
readonly Action _execute;
public RelayCommand(Action execute)
: this(execute, null)
{
}
public RelayCommand(Action execute, Func<Boolean> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
Other class's code:
public void CreateCommand()
{
RelayCommand command = new RelayCommand((param)=> RemoveReferenceExcecute(param));}
}
private void RemoveReferenceExcecute(object param)
{
ReferenceViewModel referenceViewModel = (ReferenceViewModel) param;
ReferenceCollection.Remove(referenceViewModel);
}
Why do I get the following exception, how can I fix it?
Delegate 'System.Action' does not take 1 arguments
RelayCommand command = new RelayCommand((param)=> RemoveReferenceExcecute(param));}
, which is in the question? Agreed with the sentiment, this should have been pointed out. – MagellanRelayCommand
, you have_execute
as anAction
. That's a delegate type that has 0 parameters and returnsvoid
. We can't see how_execute
is used. But it is probably something like_execute();
(note: 0 arguments). In the "other class", your methodCreateCommand
seems to create aRelayCommand
but (unless there's more inside theCreateCommand
body) it looks like it is not used or kept. The problem, as already pointed out, is that there is 1 argument on the left-hand side of your lambda arrow=>
, but the delegate you use needs 0 arguments. – ViscountessAction
toAction<object>
, then the signature of yourRemoveReferenceExcecute
would match, and this simple syntax would be allowed:command = new RelayCommand(RemoveReferenceExcecute);
(by "method group" conversion). – Viscountess(param)
would not match the parameterlessAction
– Align