WPF Application.Windows Property

Windows property is a type of a WindowCollection that gets all instantiated windows in an AppDomain. When a Window instance is created within an application or a Window XAML file is added to the project, a Window instance is automatically added to the WindowCollection. By default, the first item added to the WindowCollection is MainWindow. Windows that are created by worker threads are not added to the WindowCollection. A Window reference is automatically removed from the collection before its Closed event is raised.

The code snippet loops through all Window objects in an application and displays their titles.

foreach (Window window in Application.Current.Windows)

{

    MessageBox.Show(window.Title);
}