Window.Close Method
Closes the application window unless the Closing event is canceled.
Namespace: System.Windows
Assembly: System.Windows (in System.Windows.dll)
| Exception | Condition |
|---|---|
| NotSupportedException | The application is not running outside the browser. |
| SecurityException | 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 response to a user-initiated action, for example, in a button Click event handler.
Before the Application.Startup event has completed (that is, in an IApplicationService.StartService method, an IApplicationLifetimeAware.Starting method, or a Startup event handler).
In a trusted application.
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.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.