Share via


DesktopWindowXamlSource Class

Definition

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

/// [Windows.Foundation.Metadata.ContractVersion(Windows.UI.Xaml.Hosting.HostingContract, 196608)]
/// [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(Windows.UI.Xaml.Hosting.HostingContract), 196608)]
[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

Windows requirements

Device family
Windows Desktop Extension SDK (introduced in 10.0.17763.0)
API contract
Windows.UI.Xaml.Hosting.HostingContract (introduced in v3.0)

Remarks

DesktopWindowXamlSource is the main class in the UWP XAML hosting API. This API enables non-UWP desktop applications to host any control that derives from Windows.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). For more information, see Using the UWP XAML hosting API in a desktop application.

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

Because DesktopWindowXamlSource derives from IClosable, so 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 Windows.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.

Methods

Close()

Closes and releases any resources used by this DesktopWindowXamlSource.

Dispose()

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

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 (for example, 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