microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.78k stars 319 forks source link

XAML hosting is not working in Active Document Containment scenario #4610

Open Ajith-GS opened 1 month ago

Ajith-GS commented 1 month ago

Describe the bug

We have been using an Active Document server application that is embedded in an Active Document container application by creating an OLE object for the server application. A sample application with the same implementation is attached. We have several such kinds of server applications embedded in the same container application. As a part of the modernization, WinUI3 XAML hosting is performed, and its success full if we invoke the server application alone(standalone invoking). However if we invoke the container application, during the in-place activation of the server object using the DoVerb method, following error is occurred and the initialized DesktopWindowXamlSource is closing unexpectedly.

Msg:[HWND 0000000001031156 changed parent from 00000000011F0F7C to 0000000000F71198. Unsupported scenario.] MyActiveServer.exe: WinRT originate error - 0x8007139F : 'WindowParentChain invalid state.'.

From my understanding, the Windows App SDK 1.4 or later does not support the HWND parent chain changing while DesktopWindowXamlSource is in use, as mentioned in the GitHub issue #8900 .

But Active Document Containment is a generally using technology to embed an active document server object within another active document container as mentioned in the MSDN( https://learn.microsoft.com/en-us/cpp/mfc/active-document-containment?view=msvc-170). Why Windows App SDK is unable to support this kind of scenario?

Is there a workaround available currently to address the issue mentioned above? I would be very grateful for any assistance.

Steps to reproduce the bug

CompoundDocTest.zip contains the following projects to simulate the above scenario.

  1. Build WinUI3xTest_DLL, MyActiveServer and MyActiveContainer in Release-x64 configuration.
  2. Launch CMD with Administrator privilege and change directory to MyActiveServer.exe location.
  3. Register the MyActiveServer using the command MyActiveServer.exe /RegServer
  4. Execute MyActiveContainer.exe.
  5. Click on "Invoke MyActiveServer Application" button.

Expected behavior

XAML control from WinUI3xTest_DLL should be hosted on CMyActiveServerView successfully.

Screenshots

Standalone execution of MyActiveServer.exe. ServerApp

Execution of MyActiveContainer.exe. ContainerApp

NuGet package version

Windows App SDK 1.5.5: 1.5.240627000

Packaging type

Unpackaged

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response

mominshaikhdevs commented 1 month ago

There's no "WinUI3 XAML Island" yet. I believe this issue stems from that.

I also believe @darranrowe and @castorix can help you.

Ajith-GS commented 1 month ago

There's no "WinUI3 XAML Island" yet. I believe this issue stems from that.

I also believe @DarranRowe and @castorix can help you.

Hi, Starting with Windows App SDK Version 1.4, XAML Islands technology is available. https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/release-notes-archive/stable-channel-1.4#xaml-islands-no-longer-experimental

WinUI 3 XAML hosting (WinUI 3 user control) has been performed by referring to the official Windows App SDK samples available in the following repo. https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/Islands