Click here to Skip to main content
12,073,325 members (75,789 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

18.7K views
15 bookmarked
Posted

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

, 27 Feb 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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();
            }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Daniel Vaughan
President Outcoder
Switzerland Switzerland
Daniel Vaughan is a Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company dedicated to creating best-of-breed user experiences and leading-edge back-end solutions, using the Microsoft stack of technologies--in particular WPF, WinRT, Windows Phone, and also Xamarin.Forms.

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 Windows Phone apps including Surfy, Intellicam, and Splashbox; and is the creator of a number of popular open-source projects including Calcium SDK, and Clog.

Would you like Daniel to bring value to your organisation? Please contact

Daniel's Blog | MVP profile | Follow on Twitter

Windows 10 Experts
Surfy Industrial Browser

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.160208.1 | Last Updated 27 Feb 2010
Article Copyright 2010 by Daniel Vaughan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid