Windows apps
Collapse the table of content
Expand the table of content
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.

Window.Close Method

Closes the application window unless the Closing event is canceled.

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

public void Close()


The application is not running outside the browser.


When calling this method, except in response to a user-initiated action, the Application.Startup event has already occurred and Application.HasElevatedPermissions is false.

You use this method to provide an alternative to the window Close button. This is particularly useful in trusted applications when you hide the window title bar and border. For information, see How to: Configure an Application for Out-of-Browser Support.

You can call this method only in the following cases:

In Silverlight 5, trusted, out-of-browser applications can create multiple Window instances and manipulate them programmatically. When a window is closed either by the user or by the Close method, the instance is removed from the Windows collection and the instance becomes invalid. If you want to reuse a Window instance, handle the Closing event, set Cancel to true, and then hide the window by setting its Visibility property to Collapsed.

The following code example demonstrates the use of this method.

// Close the main window.
private void CloseButton_Click(object sender, RoutedEventArgs e)
    if (Application.Current.IsRunningOutOfBrowser)


Supported in: 5, 4

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2016 Microsoft