如何在Prism中的基于任务的DelegateCommand中使用参数



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

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

最新更新