diff --git a/src/modules/keyboardmanager/ui/XamlBridge.cpp b/src/modules/keyboardmanager/ui/XamlBridge.cpp index 33800bc3b3..1c9f08549a 100644 --- a/src/modules/keyboardmanager/ui/XamlBridge.cpp +++ b/src/modules/keyboardmanager/ui/XamlBridge.cpp @@ -227,6 +227,8 @@ void XamlBridge::OnTakeFocusRequested(winrt::Windows::UI::Xaml::Hosting::Desktop HWND XamlBridge::InitDesktopWindowsXamlSource(winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource desktopSource) { HRESULT hr = S_OK; + winrt::init_apartment(apartment_type::single_threaded); + winxamlmanager = WindowsXamlManager::InitializeForCurrentThread(); auto interop = desktopSource.as(); // Parent the DesktopWindowXamlSource object to current window @@ -258,6 +260,8 @@ void XamlBridge::ClearXamlIslands() xamlSource.Close(); } m_xamlSources.clear(); + + winxamlmanager.Close(); } // Function invoked when the window is destroyed diff --git a/src/modules/keyboardmanager/ui/XamlBridge.h b/src/modules/keyboardmanager/ui/XamlBridge.h index 1c13f19cb1..506b7fec72 100644 --- a/src/modules/keyboardmanager/ui/XamlBridge.h +++ b/src/modules/keyboardmanager/ui/XamlBridge.h @@ -17,7 +17,7 @@ public: // Constructor XamlBridge(HWND parent) : - parentWindow(parent), lastFocusRequestId(winrt::guid()) + parentWindow(parent), lastFocusRequestId(winrt::guid()), winxamlmanager(nullptr) { } @@ -37,6 +37,9 @@ private: // Stores the handle of the parent native window HWND parentWindow = nullptr; + // Window xaml manager for UI thread. + WindowsXamlManager winxamlmanager; + // Stores the GUID of the last focus request winrt::guid lastFocusRequestId;