Folkert Vreeken
Folkert Vreeken

Reputation: 1

How to use a parameter in a Task-Based DelegateCommand in Prism

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);
    }
}

Upvotes: 0

Views: 159

Answers (1)

Haukinger
Haukinger

Reputation: 10883

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; }
}

Upvotes: 0

Related Questions