When the application open, splash screen with the loading message will show, then the login window will popup in front of the splash screen. My problem now is how can I continue with when logged in successfully, the login window will disappear and the splash screen will still be displayed with different loading message and after that the splash screen will totally disappear, and finally the main window of the application will be executed? Can the startup events be updated?
Here's my code in App.xaml.cs:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
SplashScreen splashScreen = new SplashScreen();
splashScreen.Show();
var startupTask = new Task(() =>
{
//Set custom message on screen
splashScreen.Dispatcher.BeginInvoke((Action)(() => splashScreen.LoadingMsg = "Please wait..."));
Thread.Sleep(500);
splashScreen.Dispatcher.BeginInvoke((Action)(() => splashScreen.LoadingMsg = "Please provide login information..."));
Thread.Sleep(300);
});
//When loading finished, show login window
startupTask.ContinueWith(t =>
{
Login loginWindow = new Login();
//When login window is loaded, the splash screen stays behind the login window
loginWindow.Loaded += (sender, args) => splashScreen.InvalidateVisual();
this.MainWindow = loginWindow;
//Show the login window in modal mode
loginWindow.ShowDialog();
}, TaskScheduler.FromCurrentSynchronizationContext());
startupTask.Start();
}
}