Window.ShowDialog Method ()
Opens a window and returns only when the newly opened window is closed.
Assembly: PresentationFramework (in PresentationFramework.dll)
Return Value
Type: System.Nullable<Boolean>A Nullable<T> value of type Boolean that specifies whether the activity was accepted (true) or canceled (false). The return value is the value of the DialogResult property before a window closes.
| Exception | Condition |
|---|---|
| InvalidOperationException | |
| InvalidOperationException |
When a Window class is instantiated, it is not visible by default. ShowDialog shows the window, disables all other windows in the application, and returns only when the window is closed. This type of window is known as a modal window.
Modal windows are primarily used as dialog boxes. A dialog box is a special type of window that applications use to interact with users to complete tasks, such as opening files or printing documents. Dialog boxes commonly allow users to accept or cancel the task for which they were shown before the dialog box is closed. ShowDialog returns a Nullable<T>Boolean value that specifies whether the activity was accepted or canceled. The return value is the value of the DialogResult property before a window closes. For more information, see DialogResult.
A window that is opened by calling the ShowDialog method does not automatically have a relationship with the window that opened it; specifically, the opened window does not know which window opened it. This relationship can be established using the Owner property and managed using the OwnedWindows property. To support UI automation (see UI Automation Overview), Owner must be set for a window opened by calling ShowDialog.
When a modal WPF window (a window opened by calling ShowDialog) is closed, the previously activated window is reactivated. If a modal WPF window has an owner window (see Owner), the owner window is not reactivated when the modal WPF window is closed unless it was the previously activated window.
Note |
|---|
This method cannot be called when a window is hosted in a browser. |
for permission to activate a window. Associated enumeration: AllWindows
Available since 3.0
