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();
if (dialogResult.HasValue && dialogResult.Value)
{
base.OnStartup(e);
}
else
{
this.Shutdown();
}
}