我正在创建我的第一个 windows phone 8 应用程序并且我想登录所以我创建了一个 LoginViewModel 与一个 LoginModel 而不是在我的 MainPage.xaml 我将登录按钮与 LoginViewModel 中的命令绑定在一起,其中 web 服务调用发生这样
public class LoginDataViewModel
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private LoginDataINPC _loginDataData { get; set; }
private string _username {get;set; }
private string _password { get; set; }
private ICommand _loginCommand;
public LoginDataViewModel()
{
this._loginCommand = new DelegateCommand(this.LoginAction);
_loginDataData = new LoginDataINPC();
}
public ICommand LoginCommand
{
get
{
return this._loginCommand;
}
}
public LoginDataINPC DataSource
{
get { return _loginDataData; }
set
{
_loginDataData = value;
}
}
private void LoginAction(object p)
{
AuthenticateUsernamePasswordRequest request = new AuthenticateUsernamePasswordRequest();
request.UserName = _loginDataData.UserName;
request.Password = _loginDataData.Password;
CompanyUIServiceClient client = new CompanyUIService.CompanyUIServiceClient();
client.AuthenticateUsernamePasswordCompleted += client_AuthenticateUsernamePasswordCompleted;
client.AuthenticateUsernamePasswordAsync(request);
}
void client_AuthenticateUsernamePasswordCompleted(object sender, CompanyUIService.AuthenticateUsernamePasswordCompletedEventArgs e)
{
if (e.Result != null)
{
CompanyUIService.AuthenticateUsernamePasswordResponse response = new AuthenticateUsernamePasswordResponse();
try
{
response = e.Result;
}
catch (Exception ex)
{
response = null;
}
}
else
{
CompanyUIService.AuthenticateUsernamePasswordResponse response = null;
}
}
我正在调试这个并且 web 服务调用正在工作,但我的问题是如何将结果发送到视图 (MainPage.xaml),以便它会显示错误消息弹出窗口或重定向到下一个视图?