-
Notifications
You must be signed in to change notification settings - Fork 692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DesktopChildSiteBridge closes unexpectedly, throwing WindowParentChain invalid state #10231
Comments
No description provided. |
Minimal reproduction project (GitHub keeps failing to upload the file) - https://1drv.ms/u/s!Apx1hDSN2e_8vPZPGi7U0g5OGuDTBQ?e=syDRx3 |
Might be this code being mistakenly called, in which case it might be an issue with WPF itself: https://github.com/dotnet/wpf/blob/c6bff274b42ea186c4a53aab6e6447cf92aeb1e1/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs#L984. Still, perhaps the XamlHost shouldn't be being so strict and destroying its window when the parent is changed (or at least have a way to restore it). |
I just tested by toggling high contrast mode on my PC (Windows 10 22H2) with the sample I posted last year (WPF_XAML_Islands_WinUI3) by recompiling it with Windows App SDK 1.6.241114003 and I don't have this problem... |
Interesting, thanks, I'll try with your sample and see if it happens on my PC. |
@castorix I tried your sample and it doesn't have the issue, but it doesn't seem to be using HwndHost, so I guess that confirms this only happens with HwndHost. |
Also submitted to WPF repo - dotnet/wpf#10153. I think this is an issue with both WinUI 3 (closing the child window when it is reparented) and WPF (HwndHost reparenting the window for no reason) |
DesktopWindowXamlSource sits under Windows.UI.Xaml.Hosting. Transferring to WindowsAppSDK repo. |
This appears to be lifted XAML Islands in WinUI3, Microsoft.UI.XAML.hosting.DesktopWindowXAMLSource. |
Describe the bug
With WinUI 3, we can now use XamlIsland using the DesktopWindowXamlSource class. By using this class, we can create a custom HwndHost in WPF to host WinUI3 content. When doing this, however, the XamlHost's window will be destroyed in response to various unrelated actions such as toggling between high contrast mode and remoting onto a machine via RDP. If you enable all exceptions in Visual Studio, you can see that it throws an exception with the message 'WindowParentChain invalid state' when it does this.
This is a problem for various reasons. First being that the content disappears, second if we try to reinitialise the DesktopWindowXamlSource, it will throw a System.Runtime.InteropServices.COMException exception. If we try to create a new DesktopWindowXamlSource and put the content from the previous one into the new one, this causes some strange side effects, such as if a ContentDialog was open previously it will now be closed, pressing tab will do nothing and various keyboard events won't be fired. Another side effect is a bunch of exceptions will be thrown when a flyout is opened. It also results in the content disappearing for a bit before it comes back.
I checked WindowsFormsHost and the old UWP/WinUI 2 XamlHost and they don't have this issue - I checked with Spy++ and the child window handle stays the same after doing something that would close the XamlHost whereas with WinUI 3, it is destroyed.
What I think is happening is that the HwndHost is doing something WinUI 3's XamlHost doesn't like which is causing it to throw that exception and close.
Steps to reproduce the bug
Expected behavior
The window should stay open. In fact, looking at the source code for the WindowsFormsHost and UWP/WinUI 2 XamlHost, they don't even seem to account for the fact that BuildWindowCore could be called again.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003
Windows version
Windows 11 (23H2): Build 22631
Additional context
No response
The text was updated successfully, but these errors were encountered: