2

I try to create an AsyncCommand with a parameter.

I used this method but it's not working.

 public static AsyncCommand<T> Create(Func<System.Threading.Tasks.Task<T>> func)
    {

        return new AsyncCommand<T>(new Command<T>(async (x) =>  await func(x)));
    }

And when I call it with my viewmodel:

 public ICommand OnRemoveTagCommand = AsyncCommand<ResultElementRatingDto>.Create(RemoveTag);

 private async Task<ResultElementRatingDto> RemoveTag(ResultElementRatingDto ratingDto)
    {

        return null;
    }

The error is:

cannot convert from 'method group' to 'Func'

What's wrong in my code?

3
  • RemoveTag takes a DTO, where does that come from? Commented Feb 19, 2020 at 23:33
  • Comes from a binding with command parameter of a listview datatemplate Command="{ Binding OnRemoveTagCommand}" CommandParameter="{ Binding . }" Commented Feb 19, 2020 at 23:51
  • You could define the command directly like OnRemoveTagCommand= new Command(async(obj) => {}); Commented Feb 20, 2020 at 1:45

1 Answer 1

2

Depending on the overloads of Create that are available, and depending on the language version you're using, the compiler sometimes cannot resolve a method group to an unambiguous overload when only considering return types. In that case, call the method with a lambda expression:

public ICommand OnRemoveTagCommand = AsyncCommand<ResultElementRatingDto>.Create(x => RemoveTag(x));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.