I have this small piece of code.
private void Application_Startup(object sender, StartupEventArgs e)
{
WndAbout ab = new WndAbout();
ab.Show();
}
And want to show window or dialog at application startup, before other modules will be loaded.
But! When I close the showed window, the main window, which starts later is closed also!
What am I doing wrong? I’ve tried to make Showdialog() – the same situation occred.
The problem you encounter comes from the way, WPF manages the shutdown.
You can change the shutdown-behaviour through the …
… property. Change it to an approriate value:
this will help.
Another way is to set manually the
MainWindow-property to your second window.If you want to make a splashscreen only, use the splashscreen option that is available since .net 3.51. IT has the advantage that it is loaded very early in the application loading sequence, much earlier that a window can.
To do that, open the properties-tab of an image in your project-explorer and set the Build Action to SplashScreen
Update
In one of my apps I had a design that also had to show a modal dialog before showing the main window. At this time I didn’t knew about the
ShutdownMode-property.What I did was I first started a
Windowthat was invisible to the user. This was the first window and it also controled app-livetime (default behaviour of WPF). Out from this window I opened the desired dialog (a window that was showed modal). If this dialog has completed unsuccessfull, I terminated the hidden window and the app completetely closed. If the dialog resulted ok, I created the first MainWindow-instance, the user can work with.