我已经在MVVM模式中创建了一个启动画面。我从app.xaml.cs onstartup事件中显示,然后我显示登录屏幕并隐藏启动画面。在用户点击登录按钮的登录界面上,我更改了启动视图模型的消息,显示启动画面并隐藏登录画面。之后我调用服务来验证用户登录,如果一切顺利,那么我再次更改启动视图模型以进行消息更新,显示启动和关闭登录表单。我的问题是当我第二次更改启动画面消息时它没有在启动画面上显示。以下是我的代码。
public class SplashViewModel:ViewModelBase
{
private string _strMessage = "Loading";
public string Message { get { return _strMessage; }
set { _strMessage = value; OnPropertyChanged("Message"); } }
}
App.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
this.Dispatcher.UnhandledException += (s, d) =>
{
throw new NotImplementedException();
};
ShowSplash();
ShowLogin();
//BootStrapper bs = new BootStrapper();
//bs.Run();
}
private void ShowSplash()
{
sp = new Splash.Splash();
spVM = new Splash.SplashViewModel();
sp.DataContext = spVM;
sp.Show();
}
private void ShowLogin()
{
LoginControl.LoginViewModel lgVM = new LoginControl.LoginViewModel();
lg = new Login();
lg.DataContext = lgVM;
lg.LoginNotification += (s) =>
{
if (s == Infrastructure.Enums.Status.Success)
{
//sp.Message = "Loading Modules....";
//sp.ShowMessage();
lg.Close();
//sp.Show();
BootStrapper bs = new BootStrapper();
bs.Run();
}
else if(s==Infrastructure.Enums.Status.Canceled)
{
lg.Close();
sp.Close();
}
};
lg.SplashController += (show, message) =>
{
if (show)
{
spVM.Message = message;
//sp.Message = message;
//sp.ShowMessage();
sp.Show();
//sp.UpdateLayout();
}
else
sp.Hide();
};
sp.Hide();
lg.Show();
}
Login.xaml.cs
public Action<Infrastructure.Enums.Status> LoginNotification { get; set; }
public Action<bool, string> SplashController { get; set; }
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
try
{
SplashController.Invoke(true, "Authenticating...");
txtLoging.GetBindingExpression(TextBox.TextProperty).UpdateSource();
txtPassword.GetBindingExpression(Infrastructure.AttachedProperty.PasswordAssistent.PasswordValue).UpdateSource();
bool? a = txtLoging.GetValue(Validation.HasErrorProperty) as bool?;
bool? b = txtPassword.GetValue(Validation.HasErrorProperty) as bool?;
if (!a.Value && !b.Value)
{
Hide();
Service.DBOperationServiceContractClient service = new Service.DBOperationServiceContractClient();
var parm = new Service.DataContract.DBParametersDataContract()
{
ProcedureName = "AuthenticateUser",
Params = new List<Service.Entity.DBParameter>() { new Service.Entity.DBParameter() {ParameterName= "@username", ParameterValue=txtLoging.Text,ParamerterType= DbType.String }
,new Service.Entity.DBParameter() {ParameterName= "@passowrd", ParameterValue=txtPassword.Password,ParamerterType= DbType.String }}
};
var output = service.DBReadOperation(parm);
System.Threading.Thread.Sleep(7000);
if (output.ReadValue.Tables.Count > 0 && output.ReadValue.Tables[0].Rows.Count > 0)
{
//Todo Keep logged in user details
SplashController.Invoke(true, "Loading Modules....");
//System.Threading.Thread.Sleep(7000);
LoginNotification.Invoke(Infrastructure.Enums.Status.Success);
}
}
}
catch (FaultException<Service.FaultContract.Fault> ex)
{
throw ex;
}
catch (Exception exc)
{
throw exc;
}
}
我知道我已经在代码后面编写了用于登录的代码,我将把代码移到视图模型中。
请让我知道如何立即在启动画面上显示消息。