We have an application developed in WPF. i wanted to implement one functionality here.
my main window, lets call it as MainWindow. And the windows that can be opened from the MainWindow are independent. they are not child windows. They have links from main window.

MainWindow - Window1 - Window11 - Window111

MainWindow - Window2 - Window22- Window222

MainWindow - Window3 - Window33 - Window333

MainWindow - Window4 - Window44- Window444

MainWindow - Window5 - Window55 - Window555

MainWindow - Window6 - Window66- Window666

So here it goes. The first level of windows like Window1,Window2, Window3... can be directly opened from Main window. Second level opens based on selection from first level windows. Third level opens from Second level...

Now i wanted to capture all the opened windows (can be first level,second level or third level) and place them as a list in main window, in anyway possible.

Create two events in your main window, something like WindowOpened and WindowClosed. When you open another window, it calls the WindowOpened routine, and when it closes, it calls WindowClosed.

You will have to pass a reference to your main form to each form you create.

You could take a look at the Application.OpenForms collection:

string OpenForms = "";
    foreach (Form f in Application.OpenForms)
    {
        OpenForms += f.Name + ", ";
    }
    if (OpenForms.Length > 2)
        OpenForms = OpenForms.Substring(0, OpenForms.Length - 2);

    MessageBox.Show(OpenForms);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.