WindowsXamlManager.InitializeForCurrentThread Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes the WinUI XAML framework in a non-Windows App SDK (WASDK) desktop application (for example, a WPF or Windows Forms application) on the current thread.
public:
static WindowsXamlManager ^ InitializeForCurrentThread();
static WindowsXamlManager InitializeForCurrentThread();
public static WindowsXamlManager InitializeForCurrentThread();
function initializeForCurrentThread()
Public Shared Function InitializeForCurrentThread () As WindowsXamlManager
Returns
An object that contains a reference to the WinUI XAML framework.
Remarks
Call this method to initialize the internal WinUI XAML framework for the current thread in a desktop application in which you want to host Microsoft.UI.Xaml.UIElement objects in a DesktopWindowXamlSource. You need to explicitly call this method only if your application creates the Windows.UI.Xaml.UIElement objects before it creates the DesktopWindowXamlSource object that will host them. Your application should typically call this method when the parent UI object that hosts the DesktopWindowXamlSource is instantiated.
If you create a DesktopWindowXamlSource object before you create the Windows.UI.Xaml.UIElement objects that will be hosted in it, you don’t need to call this method. In this scenario, the WinUI XAML framework will be initialized for you when you instantiate the DesktopWindowXamlSource object.
This method returns a WindowsXamlManager object that contains a reference to the WinUI XAML framework. You can create as many WindowsXamlManager objects as you want on a given thread. However, because each object holds a reference to the WinUI XAML framework, you should Close (Dispose in .NET) the objects to ensure that XAML resources are eventually released.
Note
In Windows App SDK 1.4, InitializeForCurrentThread
returns a new object each time it is called.
In Windows App SDK 1.5 or later, InitializeForCurrentThread
returns the same WindowsXamlManager
instance until the DispatcherQueue on the thread shuts down.