共用方式為


DesktopWindowXamlSource 類別

定義

例如,讓傳統型應用程式 (WPF 或 Windows Forms 應用程式) 在任何與視窗句柄 (HWND) 相關聯的 UI 元素中裝載 WinUI 控件。

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 327680)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DesktopWindowXamlSource : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 327680)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class DesktopWindowXamlSource : System.IDisposable
Public Class DesktopWindowXamlSource
Implements IDisposable
繼承
Object IInspectable DesktopWindowXamlSource
屬性
實作

備註

DesktopWindowXamlSourceWindows 應用程式 SDK XAML 裝載 API 中的主要類別。 此 API 可讓非 WASDK 傳統型應用程式裝載任何衍生自 Microsoft.UI.Xaml.UIElement 的控件,該控件與與 (HWND) 視窗句柄相關聯。 此 API 可供使用 WPF、Windows Forms 和 Windows API (Win32) 建置的桌面應用程式使用。

如果您在建立將裝載於它的UIElement物件之前建立DesktopWindowXamlSource對象,裝載UIElement內容的架構可確保所有物件都初始化為相同的線程。 如果您在建立將裝載它們的 DesktopWindowXamlSource 物件之前先建立 UIElement 物件,您必須先呼叫 Microsoft.UI.Xaml.Hosting.WindowsXamlManager.InitializeForCurrentThread,才能具現化 UIElement 物件。

因為 DesktopWindowXamlSource 衍生自 IClosable,所以建議您在 .NET) 完成時 關閉它 (處置 它。

建構函式

DesktopWindowXamlSource()

初始化 DesktopWindowXamlSource 類別的新實例。

屬性

Content

取得或設定您要在傳統型應用程式中裝載的 Microsoft.UI.Xaml.UIElement 物件。

HasFocus

取得值,指出 DesktopWindowXamlSource 目前在傳統型應用程式中是否有焦點。

ShouldConstrainPopupsToWorkArea

取得或設定值,這個值表示具有類似快顯行為的控件是否應該限制為工作區。

SiteBridge

DesktopSiteBridge取得與此 DesktopWindowXamlSource 物件相關聯的 。

SystemBackdrop

取得或設定用來呈現Mica和Acrylic等材質的系統底板。

方法

Close()

關閉並釋放此 DesktopWindowXamlSource 所使用的任何資源。

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

Initialize(WindowId)

初始化 DesktopWindowXamlSource 類別的新實例。

NavigateFocus(XamlSourceFocusNavigationRequest)

嘗試以程式設計方式將焦點放在傳統型應用程式中的 DesktopWindowXamlSource

事件

GotFocus

DesktopWindowXamlSource 取得桌面應用程式中的焦點時發生 (,例如當使用者在焦點位於 DesktopWindowXamlSource) 之前的元素上按下 Tab 鍵時。

TakeFocusRequested

例如,當主機桌面應用程式收到來自 DesktopWindowXamlSource 物件的要求取回焦點 (時發生,例如,用戶位於 DesktopWindowXamlSource 中的最後一個可設定焦點元素,然後按 Tab) 。

適用於

另請參閱