DesktopWindowXamlSource DesktopWindowXamlSource DesktopWindowXamlSource DesktopWindowXamlSource Class


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).

public : sealed class DesktopWindowXamlSource : IClosable
struct winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource : IClosable
public sealed class DesktopWindowXamlSource : IDisposable
Public NotInheritable Class DesktopWindowXamlSource Implements IDisposable

Windows 10 requirements

Device family
Windows Desktop Extension SDK (introduced v10.0.17763.0)
API contract
Windows.UI.Xaml.Hosting.HostingContract (introduced v3)


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.

DesktopWindowXamlSource can only be used in one top-level window per thread. If you want to host XAML content in multiple top-level windows, each window must be on its own thread.

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.


DesktopWindowXamlSource() DesktopWindowXamlSource() DesktopWindowXamlSource() DesktopWindowXamlSource()

Initializes a new instance of the DesktopWindowXamlSource class.


Content Content Content Content

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

HasFocus HasFocus HasFocus HasFocus

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


Close() Close() Close() Close()

Closes and releases any resources used by this DesktopWindowXamlSource.

Dispose() Dispose() Dispose() Dispose()

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

NavigateFocus(XamlSourceFocusNavigationRequest) NavigateFocus(XamlSourceFocusNavigationRequest) NavigateFocus(XamlSourceFocusNavigationRequest) NavigateFocus(XamlSourceFocusNavigationRequest)

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


GotFocus GotFocus GotFocus 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 TakeFocusRequested TakeFocusRequested 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).

See also