Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
27 Feb 2010 1  
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:

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here