The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Application.Windows Property

Gets the instantiated windows in an application.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public WindowCollection Windows { get; }
/** @property */
public WindowCollection get_Windows ()

public function get Windows () : WindowCollection

You cannot use this property in XAML.

Property Value

A WindowCollection that contains references to all window objects in the current AppDomain.

A Window reference is automatically added to Windows as soon as a window is instantiated on the user interface (UI) thread; windows that are created by worker threads are not added. A Window reference is automatically removed after its Closing event has been handled and before its Closed event is raised.

By default, the first item added to the Windows property becomes the MainWindow.

This property is available only from the thread that created the Application object.

The following example demonstrates how to enumerate the Windows property to build a top-level Windows menu, which is common to multiple-document interface (MDI) applications like Microsoft Excel, or multiple-instance Single Document Interface (SDI) applications like Microsoft Word.

using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
    // Custom menu item that stores a reference to a window
    public class WindowMenuItem : MenuItem
        public Window Window = null;

<Window x:Class="CSharp.MainWindow"
  Title="CSharp" Height="300" Width="300" Activated="MainWindow_Activated"
      <MenuItem Header="_File">
        <MenuItem Name="newWindowMenuItem" Click="newWindowMenuItem_Click" Header="_New Window"></MenuItem>
        <MenuItem Name="exitMenuItem" Click="exitMenuItem_Click" Header="E_xit"></MenuItem>
      <MenuItem Name="windowMenuItem" Header="_Window">

using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
    public partial class MainWindow : Window
        public MainWindow()


        void MainWindow_Activated(object sender, EventArgs e)
            int windowCount = 0;
            foreach (Window window in Application.Current.Windows)
                WindowMenuItem menuItem = new WindowMenuItem();
                menuItem.Window = window;
                menuItem.Header = "_" + windowCount.ToString() + " Window " + windowCount.ToString();
                menuItem.Click += new RoutedEventHandler(menuItem_Click);

        void menuItem_Click(object sender, RoutedEventArgs e)
            WindowMenuItem menuItem = (WindowMenuItem)sender;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft