我将QuickCross用作我的项目的MVVM框架:https://github.com/MacawNL/QuickCross 作为指南,我创建了一个命令
public RelayCommand RegisterCommand /* Data-bindable command that calls Register(), generated with cmd snippet. Keep on one line - see http://goo.gl/Yg6QMd for why. */ { get { if (_RegisterCommand == null) _RegisterCommand = new RelayCommand(Register); return _RegisterCommand; } } private RelayCommand _RegisterCommand; public const string COMMANDNAME_RegisterCommand = "RegisterCommand";
private void Register()
{
//TODO: Check valid model
var request = new RegistrationRequest
{
FullName = FullName,
UserEmail = Email,
Password = Password,
UserType = UserType
};
var response = userClientApi.Register(request);
if (response.Succeed)
{
//TODO: handle success data
}
}
我工作得很好,但我创建了一个ASYNC函数:RegisterAsync。如何在RelayCommand中调用async方法如下:
var response = await userClientApi.RegisterAsync(request);
感谢您的阅读。
答案 0 :(得分:2)
private async void Register()
注意,虽然RelayCommand不会等待调用Register方法,但在Register方法中,执行将是串行的。