Export (0) Print
Expand All

Window.Show Method

Opens a window and returns without waiting for the newly opened window to close.

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

'Declaration
Public Sub Show
'Usage
Dim instance As Window

instance.Show
public void Show ()
public function Show ()
You cannot use methods in XAML.

Exception typeCondition

InvalidOperationException

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

When the Window class is instantiated, it is not visible by default. Show shows a window and returns immediately, without waiting for the window to be closed. Consequently, the opened window does not prevent users from interacting with other windows in the application. This type of window is called a modeless window. Common examples of modeless windows are properties windows, toolboxes, and palettes. To restrict a user to interacting with a specific window, the window must be opened by calling ShowDialog.

A window that is opened by calling Show 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.

Calling Show achieves the same end result as setting Visibility property of the Window object to Visible. However, there is a difference between the two from a timing perspective.

Calling Show is a synchronous operation that returns only after the Loaded event on the child window has been raised:

Window w = new Window();
w.Loaded += delegate { System.Console.WriteLine("This is written first."); };
w.Show();
System.Console.WriteLine("This is written last.");

Setting Visibility, however, is an asynchronous operation that returns immediately:

Window w2 = new Window();
w2.Loaded += delegate { System.Console.WriteLine("This is written last."); };
w2.Visibility = Visibility.Visible;
System.Console.WriteLine("This is written first.");

When setting Visibility, any window events you register before you set Visibility may not be raised until after the method in which you set Visibility has completed execution.

The following sample demonstrates how to open a modeless window.

// Initialize window
Window window = new Window();

// Show window modelessly
// NOTE: Returns without waiting for window to close
window.Show();

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