Iterate through open windows in wpf

I am developing an application (wpf) that has 3 windows. in the main window, the user can open another window. when the user wants to open window1, I create an instance of window1 and show that

var win1 = new Window1(); win1.Owner = this; win1.Show(); 

Now that the user wants to close the application, I want to iterate through each open window and check if this window is closed (or if it is busy to complete the operation) to close this window and close the application. my question is how to iterate through open windows? possibly using this:

 foreach (var window in Application.Current.Windows) { window. } 

but how can I detect window Window1 or Window2?

+4
source share
1 answer

You can do

 if(window is Window1) { //window is of type 'Window1'! } 

Inside the foreach loop.

+3
source

All Articles