65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.83/5 (8 votes)

Feb 23, 2010

CPOL
viewsIcon

29961

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();
            }
}