DesktopWindowXamlSource Class

Definition

Enables a desktop application (for example, a WPF or Windows Forms application) to host WinUI controls in any UI element that is associated with a window handle (HWND).

/// [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
Inheritance
Object IInspectable DesktopWindowXamlSource
Attributes
Implements

Remarks

DesktopWindowXamlSource is the primary class in the Windows App SDK XAML hosting API. This API enables non-WASDK desktop applications to host any control that derives from Microsoft.UI.Xaml.UIElement in a UI element that is associated with a window handle (HWND). This API can be used by desktop applications built using WPF, Windows Forms, and the Windows API (Win32).

If you create a DesktopWindowXamlSource object before you create the UIElement objects that will be hosted in it, the framework for hosting UIElement content ensures all the objects are initialized to the same thread. If you create the UIElement objects before you create the DesktopWindowXamlSource object in which they will be hosted, you must call Microsoft.UI.Xaml.Hosting.WindowsXamlManager.InitializeForCurrentThread before you instantiate the UIElement objects.

Because DesktopWindowXamlSource derives from IClosable, it is recommended that you Close it (Dispose it in .NET) when you’re finished with it.

Constructors

DesktopWindowXamlSource()

Initializes a new instance of the DesktopWindowXamlSource class.

Properties

Content

Gets or sets the Microsoft.UI.Xaml.UIElement object that you want to host in the desktop application.

HasFocus

Gets a value that indicates whether the DesktopWindowXamlSource currently has focus in the desktop application.

ShouldConstrainPopupsToWorkArea

Gets or sets a value that indicates whether controls with popup-like behavior should be constrained to the work area.

SiteBridge

Gets the DesktopSiteBridge associated with this DesktopWindowXamlSource object.

SystemBackdrop

Gets or sets the system backdrop used to render materials like Mica and Acrylic.

Methods

Close()

Closes and releases any resources used by this DesktopWindowXamlSource.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Initialize(WindowId)

Initializes a new instance of the DesktopWindowXamlSource class.

NavigateFocus(XamlSourceFocusNavigationRequest)

Attempts to programmatically give focus to the DesktopWindowXamlSource in the desktop application.

Events

GotFocus

Occurs when the DesktopWindowXamlSource gets focus in the desktop application (such as when the user presses the Tab key while focus is on the element just before the DesktopWindowXamlSource).

TakeFocusRequested

Occurs when the host desktop application receives a request take back focus from the DesktopWindowXamlSource object (for example, the user is on the last focusable element in the DesktopWindowXamlSource and presses Tab).

Applies to

See also