Window.Show Window.Show Window.Show Window.Show Method

Definición

Abre una ventana y devuelve un valor sin esperar a que se cierre la ventana que acaba de abrirse.Opens a window and returns without waiting for the newly opened window to close.

public:
 void Show();
public void Show ();
member this.Show : unit -> unit
Public Sub Show ()

Excepciones

Se llama a Show() en una ventana que se está cerrando (Closing) o se ha cerrado (Closed).Show() is called on a window that is closing (Closing) or has been closed (Closed).

Ejemplos

En el ejemplo siguiente se muestra cómo abrir una ventana no modal.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();
' Initialize window
Dim window As New Window()

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

Comentarios

Cuando se Window crea una instancia de la clase, no es visible de forma predeterminada.When the Window class is instantiated, it is not visible by default. Showmuestra una ventana y vuelve inmediatamente, sin esperar a que se cierre la ventana.Show shows a window and returns immediately, without waiting for the window to be closed. Por lo tanto, la ventana abierta no impide que los usuarios interactúen con otras ventanas en la aplicación.Consequently, the opened window does not prevent users from interacting with other windows in the application. Este tipo de ventana se denomina ventana no modal .This type of window is called a modeless window. Algunos ejemplos comunes de ventanas no modales son las ventanas de propiedades, los cuadros de herramientas y las paletas.Common examples of modeless windows are properties windows, toolboxes, and palettes. Para impedir que un usuario interactúe con una ventana específica, se debe abrir la ventana mediante una llamada ShowDialoga.To restrict a user to interacting with a specific window, the window must be opened by calling ShowDialog.

Una ventana que se abre mediante una Show llamada a no tiene automáticamente una relación con la ventana que la abrió; en concreto, la ventana abierta no sabe qué ventana la abrió.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. Esta relación se puede establecer utilizando la Owner propiedad y administrada mediante OwnedWindows la propiedad.This relationship can be established using the Owner property and managed using the OwnedWindows property.

Al Show llamar a se obtiene el mismo resultado final Visibility que al establecer Window la propiedad Visibledel objeto en.Calling Show achieves the same end result as setting Visibility property of the Window object to Visible. Sin embargo, hay una diferencia entre los dos desde una perspectiva de tiempo.However, there is a difference between the two from a timing perspective.

Llamar Show a es una operación sincrónica que devuelve solo después de Loaded que se haya generado el evento en la ventana secundaria: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.");
Dim w As New Window()
AddHandler w.Loaded, Sub() System.Console.WriteLine("This is written first.")
w.Show()
System.Console.WriteLine("This is written last.")

Sin Visibilityembargo, el valor es una operación asincrónica que devuelve inmediatamente: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.");
Dim w2 As New Window()
AddHandler w2.Loaded, Sub() System.Console.WriteLine("This is written last.")
w2.Visibility = Visibility.Visible
System.Console.WriteLine("This is written first.")

Al establecer Visibility, es posible que los eventos de ventana que Visibility se registren antes de establecer no se generen hasta que Visibility el método en el que ha establecido se haya completado la ejecución.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.

Se aplica a

Consulte también: