peter.mcclymont@gmail.com
10/5/2008 11:00:00 PM
On Oct 6, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Thu, 02 Oct 2008 20:06:47 -0700, peter.mcclym...@gmail.com
>
> <peter.mcclym...@gmail.com> wrote:
> > [...]
> > Well, anyway that is the gist. The problem is that CustomDialog2 does
> > not display. I can step over the ShowDialog method and it seems to do
> > nothing. If I check DialogResult after the call to cd2.ShowDialog() it
> > is null.
>
> > The other thing I did was swap the dialogs over, e.g. displayed
> > CustomDialog2 then CustomDialog. CustomDialog was the one to fail this
> > time, so it seems that the second dialog to display will fail. It
> > doesn't seem to relate to the actual dialog classes
>
> > Any ideas?
>
> The problem here is that the Application object is automatically shutting
> down your program when the first dialog is closed. Once that happens, no
> other windows will be shown, including the second dialog.
>
> If you want to write your application this way, then in your Shutdown
> handler, you should set the Application.ShutdownMode property to
> ShutdownMode.OnExplicitShutdown. Then, in your main window override the
> OnClosed() method and call the Application.Shutdown() method so that the
> application will quit when that window is closed (or alternatively, call
> that method where appropriate for shutting down the application).
>
> For example, in your Application sub-class ("App" by default):
>
> private void App_Startup(object sender, StartupEventArgs e)
> {
> Window dialog = new Dialog1();
>
> ShutdownMode = ShutdownMode.OnExplicitShutdown;
>
> if (dialog.ShowDialog() == true)
> {
> Window window = new Window1();
>
> window.Show();
> }
> else
> {
> Shutdown();
> }
> }
>
> (I only show a single dialog here, but I hope the general technique is
> clear)
>
> Then in your main window class:
>
> protected override void OnClosed(EventArgs e)
> {
> base.OnClosed(e);
>
> Application.Current.Shutdown();
> }
>
> Alternatively, you could use ShutdownMode.OnMainWindowClose. That would
> allow you to avoid having to override the OnClosed() method, but you'd
> have to either set the MainWindow property explicitly or make sure that
> you create the main window first (and if you don't want to create the main
> window until you're sure you're going to show it, you'd need to explicitly
> set MainWindow to null after creating each dialog but before showing it).
>
> Pete
Thank you so much, that is exactly the answer there. I am not used to
a framework having some control of that kind of stuff. It's all
working now!!