0

我可以在基于任务的 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);
    }
}
4

1 回答 1

0

我可以在基于任务的 DelegateCommand 中使用参数吗?

当然。

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; }
}
于 2020-02-28T07:47:55.770 回答