From 204fc82e2ceb283c98dc52087d5cf77da45f7737 Mon Sep 17 00:00:00 2001 From: MouriNaruto Date: Sun, 31 Dec 2023 13:56:06 +0800 Subject: [PATCH] Add "Prevent showing the dummy/empty/ghost DesktopWindowXamlSource window in the task bar" workaround from Mile.Xaml.Native for Mile.Xaml.Managed. --- .../XamlApplicationExtensions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Mile.Xaml.Managed/XamlApplicationExtensions.cs b/Mile.Xaml.Managed/XamlApplicationExtensions.cs index b1490bc..0befa31 100644 --- a/Mile.Xaml.Managed/XamlApplicationExtensions.cs +++ b/Mile.Xaml.Managed/XamlApplicationExtensions.cs @@ -38,6 +38,9 @@ private static extern IntPtr DispatchMessage( [ThreadStatic] private static WindowsXamlManager XamlManager = null; + [ThreadStatic] + private static System.Windows.Forms.Form CoreWindowHostWindow = null; + public static void ThreadInitialize( this Application BaseObject) { @@ -47,6 +50,22 @@ public static void ThreadInitialize( } BaseObject.SetTransparentBackgroundAttribute(true); + + // Prevent showing the dummy/empty/ghost DesktopWindowXamlSource window + // in the task bar. + // Reference: https://github.com/microsoft/terminal/issues/6507 + // Reference: https://github.com/microsoft/microsoft-ui-xaml/issues/6490 + // Fixes: https://github.com/M2Team/NanaZip/issues/225 + // For also fixing the window with empty content due to CoreWindow is + // not exist issue, create a host window without message loop is a + // better workaround. + if (CoreWindowHostWindow == null) + { + CoreWindowHostWindow = new System.Windows.Forms.Form(); + CoreWindowHostWindow.Controls.Add(new WindowsXamlHost()); + CoreWindowHostWindow.Show(); + CoreWindowHostWindow.Hide(); + } } public static void ThreadUninitialize(