Window Class
Definition
public ref class Window sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.IWindowStatics, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class Window sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
/// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.IWindowStatics, 65536, "Windows.Foundation.UniversalApiContract")]
class Window sealed
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.IWindowStatics), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class Window
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.IWindowStatics), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class Window
Public NotInheritable Class Window
- Inheritance
-
Window
- Attributes
Windows 10 requirements
Device family |
Windows 10 (introduced in 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced in v1.0)
|
Examples
The following code example shows the OnLaunched method override generated for the blank application template in Microsoft 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();
}
Protected Overrides Sub OnLaunched(args As
Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
' Create a Frame to act navigation context and navigate to the first page
Dim rootFrame As New Frame()
rootFrame.Navigate(GetType(BlankPage))
' Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame
Window.Current.Activate()
End Sub
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 Microsoft 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.
Version history
Windows version | SDK version | Value added |
---|---|---|
1703 | 15063 | Compositor |
1903 | 18362 | UIContext |
Properties
Bounds |
Gets a Rect value containing the height and width of the application window in units of effective (view) pixels. Equivalent WinUI property: Microsoft.UI.Xaml.Window.Bounds. |
Compositor |
Gets the Compositor for this window. Equivalent WinUI property: Microsoft.UI.Xaml.Window.Compositor. |
Content |
Gets or sets the visual root of an application window. Equivalent WinUI property: Microsoft.UI.Xaml.Window.Content. |
CoreWindow |
Gets an internal core object for the application window. Equivalent WinUI property: Microsoft.UI.Xaml.Window.CoreWindow. |
Current |
Gets the window of the current thread. Equivalent WinUI property: Microsoft.UI.Xaml.Window.Current. |
Dispatcher |
Gets the CoreDispatcher object for the Window, which is generally the CoreDispatcher for the UI thread. Equivalent WinUI property: Microsoft.UI.Xaml.Window.Dispatcher. |
UIContext |
Gets the context identifier for the window. |
Visible |
Gets a value that reports whether the window is visible. Equivalent WinUI property: Microsoft.UI.Xaml.Window.Visible. |
Methods
Activate() |
Attempts to activate the application window by bringing it to the foreground and setting the input focus to it. Equivalent WinUI method: Microsoft.UI.Xaml.Window.Activate. |
Close() |
Closes the application window. Equivalent WinUI method: Microsoft.UI.Xaml.Window.Close. |
SetTitleBar(UIElement) |
Makes a XAML element interact with the system as if it’s the title bar. |
Events
Activated |
Occurs when the window has successfully been activated. Equivalent WinUI event: Microsoft.UI.Xaml.Window.Activated. |
Closed |
Occurs when the window has closed. Equivalent WinUI event: Microsoft.UI.Xaml.Window.Closed. |
SizeChanged |
Occurs when the app window has first rendered or has changed its rendering size. Equivalent WinUI event: Microsoft.UI.Xaml.Window.SizeChanged. |
VisibilityChanged |
Occurs when the value of the Visible property changes. Equivalent WinUI event: Microsoft.UI.Xaml.Window.VisibilityChanged. |