Window 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示应用程序窗口。
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.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Window final
	[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)]
public sealed class Window
	Public NotInheritable Class Window
		- 继承
 
- 属性
 
Windows 要求
| 设备系列 | 
					 
							Windows 10 (在 10.0.10240.0 中引入) 
				 | 
			
| API contract | 
					 
							Windows.Foundation.UniversalApiContract (在 v1.0 中引入) 
				 | 
			
示例
下面的代码示例演示为 Microsoft Visual Studio 中的空白应用程序模板生成的 OnLaunched 方法替代。 此代码演示 Current 和 Content 属性以及 Activate 方法的典型使用模式。
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
	注解
此类表示当前 应用程序的窗口。 静态 Current 属性将以与静态 Application 属性相同的方式返回应用窗口对象。 从此对象中,应用可以利用 调度程序 或通过 Bounds 属性确定窗口的大小。 Window 最常见的用法是将 UIElement 设置为代表应用 UI 的内容 。 这通常作为应用激活 (的一部分来完成,例如 OnLaunched override.) 可以在窗口的整个生存期内更改此窗口内容。
Window 类没有 XAML 表示形式,因为它不是控件。
Window 对象只是显示 来自 CoreWindow 的信息,而 CoreWindow 又引用系统创建的窗口。
请确保在初始 激活 时使用的任何 Window 上调用 Activate。 如果使用 Microsoft Visual Studio 中的默认应用模板,则调用 Window.Activate 是 app.xaml 代码隐藏文件中初始代码的一部分。
属于 Microsoft Visual Studio 中某些应用程序模板的 LayoutAwarePage 类具有 SizeChanged 事件的处理,该事件用于跟踪与 ApplicationViewState 值匹配的视觉状态。 LayoutAwarePage 还有一些代码,用于检查 边界 ,并使用此值来影响如何处理页面范围的输入事件。
版本历史记录
| Windows 版本 | SDK 版本 | 已添加值 | 
|---|---|---|
| 1703 | 15063 | Compositor | 
| 1903 | 18362 | UIContext | 
其他接口成员
| IXamlSourceTransparency.IsBackgroundTransparent | 获取或设置一个值,该值指定当前线程上所有 DesktopWindowXamlSource 对象的背景是否透明。 | 
属性
| Bounds | 
		 获取一个 Rect 值,该值包含窗口工作区的原点、高度和宽度,以与设备无关的像素 (DIP) 。  | 
        	
| Compositor | 
		 获取此窗口的 Compositor 。  | 
        	
| Content | 
		 获取或设置应用程序窗口的可视根。  | 
        	
| CoreWindow | 
		 获取应用程序窗口的内部 核心 对象。  | 
        	
| Current | 
		 获取当前线程的窗口。  | 
        	
| Dispatcher | 
		 获取 Window 的 CoreDispatcher 对象,该对象通常是 UI 线程的 CoreDispatcher 对象。  | 
        	
| UIContext | 
		 获取窗口的上下文标识符。  | 
        	
| Visible | 
		 获取一个值,该值报告窗口是否可见。  | 
        	
方法
| Activate() | 
		 尝试通过将应用程序窗口置于前台并为其设置输入焦点来激活它。  | 
        	
| Close() | 
		 关闭应用程序窗口。  | 
        	
| SetTitleBar(UIElement) | 
		 使 XAML 元素与系统交互,就像它是标题栏一样。  | 
        	
事件
| Activated | 
		 成功激活窗口时发生。  | 
        	
| Closed | 
		 在窗口关闭时发生。  | 
        	
| SizeChanged | 
		 当应用窗口首次呈现或更改其呈现大小时发生。  | 
        	
| VisibilityChanged | 
		 当 Visible 属性的值更改时发生。  |