This documentation is archived and is not being maintained.

Window.Close Method

Manually closes a Window.

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

public void Close()

A Window can be closed using one of several, well-known, system-provided mechanisms located in its title bar, including:

  • ALT+F4.

  • System menu | Close.

  • Close button.

A Window can also be closed using one of several well-known mechanisms within the client area that are provided by developers, including:

  • File | Exit on a main window.

  • File | Close or a Close button on a child window.


OK and Cancel buttons on a dialog box are also developer-provided, although will likely set DialogResult, which automatically closes a window that was opened by calling ShowDialog.

These mechanisms require you to explicitly call Close to close a window.


If a window, opened by calling ShowDialog, and with a Button with its IsCancel property set to true, will automatically close when the button is either clicked, or ESC is pressed. If the window was opened using Show, however, Close must be explicitly called, such as from Click event handler for the Button.

Closing a window causes the Closing event to be raised. If the Closing event isn't canceled, the following occurs:

Closing a Window causes any windows that it owns to be closed. Furthermore, closing a Window may cause an application to stop running depending on how the Application.ShutdownMode property is set.


This method cannot be called when a window is hosted in a browser.

The following example shows a File | Exit menu being handled to explicitly call Close.

<MenuItem Name="fileExitMenuItem" Header="E_xit" Click="fileExitMenuItem_Click"></MenuItem>

void fileExitMenuItem_Click(object sender, RoutedEventArgs e)
    // Close this window

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • UIPermission 

    for permission to use all windows and user input events without restriction. Associated enumeration: AllWindows

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.