I wanted my app to have a login window as well as a main window. Default WPF implementation closes the app whenever the main window is closed, which prevented me from closing the window during a logoff/logon procedure.
I found the ‘Startup’ attribute and overrode it to provide the functionality I was looking for.
<Application x:Class="DSI.MobileClient.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources>
</Application.Resources>
</Application>
And in app.xaml.cs:
void Application_Startup(object sender, StartupEventArgs e) {
Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
do {
if (!Login())
break;
MainWindow window = new MainWindow();
if (window.ShowDialog() == false)
break;
} while (true);
Shutdown();
}
