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();
}
}
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.
Previously Daniel was a nine-time Microsoft MVP and co-founder of
Outcoder, a Swiss software and consulting company.
Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.
Daniel is the developer behind several acclaimed mobile apps including
Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably
Codon.
Would you like Daniel to bring value to your organisation?
Please contact
Blog |
Twitter
Xamarin Experts
Windows 10 Experts