Window クラス

定義

現在の アプリケーションのウィンドウを表します。

/// [Microsoft.UI.Xaml.Markup.ContentProperty(Name="Content")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Window
[Microsoft.UI.Xaml.Markup.ContentProperty(Name="Content")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class Window
Public Class Window
継承
Object IInspectable Window
属性

Onlaunched

次のコード例は、Microsoft Visual Studio のデスクトップ テンプレートの WinUI に対して生成された OnLaunched メソッドのオーバーライドを示しています。 このコードは、Windowでの Activate メソッドの一般的な使用方法を示しています。

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
    m_window = new MainWindow();
    m_window.Activate();
}

private Window m_window;

新しいウィンドウを作成する

アプリでは、各ウィンドウを明示的に作成できます。 複数のウィンドウを作成するには、Windows アプリ SDKに対する 1.0.1 更新が必要であり、1 つのスレッドに制限されます。

var window = new Window();
window.Content = new TextBlock() { Text = "Hello" };
window.Activate();

マークアップで新しいウィンドウを定義することもできます。

<Window 
    x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock>Hello</TextBlock>
</Window>

対応する分離コード:

public partial class MainWindow : Window
{
  public MainWindow()
  {
    InitializeComponent();
  }
}

...
MainWindow window = new MainWindow();
window.Activate();

注釈

詳細と例については、WinUI とWindows アプリ SDKのウィンドウの概要を参照してください。

通常、Windowは、アプリの UI を表すコンテンツUIElement を設定するために使用されます。 これは通常、アプリのアクティブ化 ( OnLaunched オーバーライドなど) の一部として行われ、ウィンドウの有効期間を通じてウィンドウの内容を変更できます。

最初の アクティブ化 で使用 Window に対して Activate を呼び出していることを確認します。 Microsoft Visual Studioの既定のアプリ テンプレートを使用する場合、Window.ActivateApp.xaml分離コード ファイルに含まれます。

アプリ内のスレッドごとに複数の Window を作成できます。 「アプリに複数のウィンドウを表示する」を参照してください

Windowは、Window の HWND (WindowHandle) を介して相互運用を有効にする IWindowNative を実装します。

コンストラクター

名前 説明
Window()

Window クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
AppWindow

この XAML Windowに関連付けられているAppWindowを取得します。

Bounds

有効な (ビュー) ピクセルの単位でアプリケーション ウィンドウの高さと幅を含む Rect 値を取得します。

Compositor

このウィンドウの コンポジター を取得します。

Content

アプリケーション ウィンドウのビジュアル ルートを取得または設定します。

CoreWindow

[非推奨]常に nullを返します。

Current

常に null を返します。

Dispatcher

[非推奨]常に nullを返します。

DispatcherQueue

ウィンドウの DispatcherQueue オブジェクトを取得します。

ExtendsContentIntoTitleBar

アプリ コンテンツの領域を作成するために、ウィンドウの既定のタイトル バーを非表示にするかどうかを指定する値を取得または設定します。

Height

現在の アプリケーションのウィンドウを表します。

MaxHeight

現在の アプリケーションのウィンドウを表します。

MaxWidth

現在の アプリケーションのウィンドウを表します。

MinHeight

現在の アプリケーションのウィンドウを表します。

MinWidth

現在の アプリケーションのウィンドウを表します。

SystemBackdrop

この Windowに適用するシステム背景を取得または設定します。 背景は、 Window コンテンツの背後にレンダリングされます。

Title

ウィンドウ タイトルに使用される文字列を取得または設定します。

Visible

ウィンドウが表示されているかどうかを報告する値を取得します。

Width

現在の アプリケーションのウィンドウを表します。

メソッド

名前 説明
Activate()

フォアグラウンドに移動し、入力フォーカスを設定して、アプリケーション ウィンドウのアクティブ化を試みます。

Close()

アプリケーション ウィンドウを閉じます (破棄します)。

SetTitleBar(UIElement)

ExtendsContentIntoTitleBartrueされている場合に XAML 要素のタイトル バーの動作を有効にします。

イベント

名前 説明
Activated

ウィンドウが正常にアクティブ化または非アクティブ化されたときに発生します。

Closed

ウィンドウが閉じられたときに発生します。

SizeChanged

ウィンドウのレンダリング サイズが変更されたときに発生します。

VisibilityChanged

Visible プロパティの値が変更されたときに発生します。

適用対象

こちらもご覧ください