Mostafa Khodakarami
Mostafa Khodakarami

Reputation: 830

WPF: application shutdown after closing a window

I am new to WPF. I have two windows that are opening in app.xaml.cs.

In app.xaml.cs I open w1 and after some operations w1 will close. Then w2 automatically open. As below:

public partial class App : Application
{
    public App()
    {
        w1 a = new w2();
        a.ShowDialog();
        a = null;

        w2 b = new w2();
        b.ShowDialog();
        b = null;
    }
}

After a closed, b is not showing and application is shutting down.

In c# this codes are working in program.cs. What is deference and what should I do?

Upvotes: 0

Views: 437

Answers (2)

Dark Templar
Dark Templar

Reputation: 1155

you can add an event to your first window that will open the second window once it's closed, something similar to this:

    public partial class App : Application
    {
        public App()
        {
            w1 a = new w2();
            a.Closed += a_Closed;
            a.ShowDialog();
            a = null;
        }
    }

then under the closed event of the first window create the second window:

    private void a_Closed(object sender, EventArgs e)
    {
        w2 b = new w2();
        b.ShowDialog();
        b = null; ;
    }

Upvotes: 1

Timothy Ghanem
Timothy Ghanem

Reputation: 1616

See this:

Application.ShutdownMode Property

In your case i guess you should be using OnExplicitShutdown and then call Application.Shutdown Method after your second window closes.

Upvotes: 2

Related Questions