Export (0) Print
Expand All

Window.ShowDialog Method

Opens a window and returns only when the newly opened window is closed.

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

public Nullable<bool> ShowDialog ()
public Nullable<boolean> ShowDialog ()
public function ShowDialog () : Nullable<boolean>
You cannot use methods in XAML.

Return Value

Returns a NullableBoolean value that signifies how a window was closed by the user.

Exception typeCondition

InvalidOperationException

ShowDialog is called on a Window that is visible

-or-

ShowDialog is called on a visible Window that was opened by calling ShowDialog.

InvalidOperationException

ShowDialog is called on a window that is closing (Closing) or has been closed (Closed).

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 NullableBoolean value that specifies whether the activity was accepted or cancelled. The return value is the value of the DialogResult property before a window closes (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.

NoteNote:

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

The following sample demonstrates how to open a modal window.

// Instantiate window
DialogBox dialogBox = new DialogBox();

// Show window modally
// NOTE: Returns only when window is closed
Nullable<bool> dialogResult = dialogBox.ShowDialog();

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

Community Additions

ADD
Show:
© 2014 Microsoft