Click here to Skip to main content
15,886,770 members
Articles / Desktop Programming / WPF
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.83/5 (10 votes)
27 Feb 2010CPOL 29.7K   15  
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Switzerland Switzerland
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

Comments and Discussions

 
-- There are no messages in this forum --