Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Window class

Applies to Windows and Windows Phone

Represents an application window.

Inheritance

Object
  Window

Syntax


public sealed class Window

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The Window class has these types of members:

Events

The Window class has these events.

EventDescription
Activated Occurs when the window has successfully been activated.
Closed Occurs when the window has closed.
SizeChanged Occurs when the app window has first rendered or has changed its rendering size.
VisibilityChanged Occurs when the value of the Visible property changes.

 

Methods

The Window class has these methods. It also inherits methods from the Object class.

MethodDescription
Activate Attempts to activate the application window by bringing it to the foreground and setting the input focus to it.
Close Closes the application window.

 

Properties

The Window class has these properties.

PropertyAccess typeDescription

Bounds

Read-onlyGets the height and width of the application window, as a Rect value.

Content

Read/writeGets or sets the visual root of an application window.

CoreWindow

Read-onlyGets an internal core object for the application window.

Current

Read-onlyGets the currently activated window for an application.

Dispatcher

Read-onlyGets the CoreDispatcher object for the Window, which is generally the CoreDispatcher for the UI thread.

Visible

Read-onlyGets a value that reports whether the window is visible.

 

Remarks

This class represents the window of the current Application. In the same manner as the static Application property, the static Current property will return the app window object. From this object, an app can utilize the Dispatcher or determine the size of the Window from the Bounds property. The most common usage for Window is setting a UIElement to the Content that represents the app UI. This is usually done as part of app activation (for example in the OnLaunched override.) You can change this window content throughout the lifetime of the window.

There is no XAML representation of the Window class because it is not a control.

A Window object is just surfacing information from CoreWindow, which in turn is referencing the window created by the system.

Make sure to call Activate on any Window you use on initial activation. If you use the default app templates from Microsoft Visual Studio, calling Window.Activate is part of the initial code in the app.xaml code-behind file.

The LayoutAwarePage class that is part of some application templates in Visual Studio has handling for the SizeChanged event, which is used for keeping track of visual states that match values of ApplicationViewState. LayoutAwarePage also has code that checks Bounds and uses this value to influence how page-wide input events are handled.

Examples

The following code example shows the OnLaunched method override generated for the blank application template in Visual Studio. This code demonstrates typical usage patterns for the Current and Content properties and the Activate method.


protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    // Create a Frame to act navigation context and navigate to the first page
    var rootFrame = new Frame();
    rootFrame.Navigate(typeof(BlankPage));

    // Place the frame in the current Window and ensure that it is active
    Window.Current.Content = rootFrame;
    Window.Current.Activate();
}


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

OnLaunched
How to activate an app
CoreWindow

 

 

Show:
© 2014 Microsoft