Window 類別

定義

表示應用程式視窗。

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
繼承
Object Platform::Object IInspectable Window
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

下列程式碼範例顯示針對 Microsoft Visual Studio 中空白應用程式範本產生的 OnLaunched 方法覆寫。 此程式碼示範 CurrentContent 屬性和 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

備註

這個類別代表目前 應用程式的視窗。 與靜態 Application 屬性相同,靜態 Current 屬性會傳回應用程式視窗物件。 從這個物件中,應用程式可以使用 發送器 ,或從 Bounds 屬性判斷 Window 的大小。 Window 最常見的用法是將 UIElement 設定為代表應用程式 UI 的內容 。 這通常是在應用程式啟用 (的一部分完成,例如 OnLaunched override.) 您可以在視窗的存留期內變更此視窗內容。

Window 類別沒有 XAML 標記法,因為它不是控制項。

Window 物件只是從 CoreWindow呈現資訊,接著會參考系統所建立的視窗。

請務必在初始啟用時使用的任何視窗上呼叫 Activate 。 如果您使用 Microsoft Visual Studio 的預設應用程式範本,則呼叫 Window.Activate 是 app.xaml 程式碼後置檔案中初始程式碼的一部分。

屬於 Microsoft Visual Studio 中某些應用程式範本的 LayoutAwarePage 類別具有 SizeChanged 事件的處理,其用於追蹤符合 ApplicationViewState值的視覺狀態。 LayoutAwarePage 也有程式碼會檢查 界限 ,並使用此值來影響整個頁面輸入事件的處理方式。

版本歷程記錄

Windows 版本 SDK 版本 已新增值
1703 15063 撰寫器
1903 18362 UIContext

其他介面成員

IXamlSourceTransparency.IsBackgroundTransparent取得或設定值,指定目前線程上所有 DesktopWindowXamlSource 物件的背景是否透明。

屬性

Bounds

取得 Rect 值,其中包含視窗工作區的原點、高度和寬度,以裝置無關的圖元 (DIP) 。

Compositor

取得這個視窗的 Compositor

Content

取得或設定應用程式視窗的視覺根目錄。

CoreWindow

取得應用程式視窗的內部 核心 物件。

Current

取得目前線程的視窗。

Dispatcher

取得WindowCoreDispatcher物件,這通常是 UI 執行緒的CoreDispatcher

UIContext

取得視窗的內容識別碼。

Visible

取得值,這個值會報告視窗是否可見。

方法

Activate()

嘗試將應用程式視窗帶入前景,並將輸入焦點設定為它來啟動應用程式視窗。

Close()

關閉應用程式視窗。

SetTitleBar(UIElement)

讓 XAML 元素與系統互動,就像是標題列一樣。

事件

Activated

當視窗成功啟動時發生。

Closed

當視窗關閉時發生。

SizeChanged

發生于應用程式視窗第一次轉譯或變更其轉譯大小時。

VisibilityChanged

發生于 Visible 屬性的值變更時。

適用於

另請參閱