Displaying a Custom Dialog in WPF Before the Main Application Window is Shown






4.83/5 (8 votes)
In a WPF application, the first window opened is deemed to be the main window. In order to prevent an application from closing when an initial dialog is closed, use the Application.Current.ShutdownMode property as demonstrated in the following example:protected override void...
In a WPF application, the first window opened is deemed to be the main window. In order to prevent an application from closing when an initial dialog is closed, use the
Application.Current.ShutdownMode
property as demonstrated in the following example:
protected override void OnStartup(StartupEventArgs e)
{
Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
CustomDialog dialog = new CustomDialog ();
bool? dialogResult = auth.ShowDialog();
/* Handle results */
if (dialogResult.HasValue && dialogResult.Value)
{
base.OnStartup(e);
}
else
{
this.Shutdown();
}
}