0

Can I use a parameter in a task-based DelegateCommand (Prism.Commands):

(https://prismlibrary.com/docs/commanding.html)

public class ArticleViewModel
{
    public DelegateCommand SubmitCommand { get; private set; }

    public ArticleViewModel()
    {
        SubmitCommand = new DelegateCommand<object>(async ()=> await Submit());
    }

    Task Submit(object parameter)
    {
        return SomeAsyncMethod(parameter);
    }
}
Brydenr
  • 798
  • 1
  • 19
  • 30

1 Answers1

0

Can I use a parameter in a task-based DelegateCommand?

Sure.

internal class ArticleViewModel : BindableBase
{
    public ArticleViewModel()
    {
        SubmitCommandWithMethodGroup = new DelegateCommand<object>( SomeAsyncMethod );
        SubmitCommandWithLambda = new DelegateCommand<object>( async x => { var y = await Something(x); await SomethingElse(y); } );
    }

    public DelegateCommand<object> SubmitCommandWithMethodGroup { get; }
    public DelegateCommand<object> SubmitCommandWithLambda { get; }
}
Haukinger
  • 10,420
  • 2
  • 15
  • 28