From 034759f949360b426f63c9aadca1efcf9fa2e08c Mon Sep 17 00:00:00 2001 From: Shawn Yuan <128874481+shuaiyuanxx@users.noreply.github.com> Date: Fri, 6 Feb 2026 16:58:29 +0800 Subject: [PATCH] Fix WinuiEx crash issue (#45443) ## Summary of the Pull Request Fixes a crash related to `IsShownInSwitchers` when explorer.exe is not running. The property has been removed from XAML and is now set in the C# backend with added exception handling to improve stability. No changes were made for projects where the property is set to true, as they are not affected. ## PR Checklist - [ ] Closes: #xxx - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --------- Co-authored-by: vanzue --- .../MeasureToolUI/MeasureToolXAML/MainWindow.xaml | 1 - .../MeasureToolXAML/MainWindow.xaml.cs | 13 ++++++++++++- .../QuickAccess.UI/QuickAccessXAML/MainWindow.xaml | 1 - .../QuickAccessXAML/MainWindow.xaml.cs | 12 +++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml b/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml index 4a4f3dd8b0..5ae5e6e4c1 100644 --- a/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml +++ b/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml @@ -10,7 +10,6 @@ IsMaximizable="False" IsMinimizable="False" IsResizable="False" - IsShownInSwitchers="False" IsTitleBarVisible="False" mc:Ignorable="d"> diff --git a/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml.cs b/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml.cs index 4f807655da..afc59eb8d3 100644 --- a/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml.cs +++ b/src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml.cs @@ -52,12 +52,23 @@ namespace MeasureToolUI var presenter = _appWindow.Presenter as OverlappedPresenter; presenter.IsAlwaysOnTop = true; this.SetIsAlwaysOnTop(true); - this.SetIsShownInSwitchers(false); this.SetIsResizable(false); this.SetIsMinimizable(false); this.SetIsMaximizable(false); IsTitleBarVisible = false; + try + { + this.SetIsShownInSwitchers(false); + } + catch (NotImplementedException) + { + // WinUI will throw if explorer is not running, safely ignore + } + catch (Exception) + { + } + // Remove the caption style from the window style. Windows App SDK 1.6 added it, which made the title bar and borders appear for Measure Tool. This code removes it. var windowStyle = GetWindowLong(hwnd, GWL_STYLE); windowStyle = windowStyle & (~WS_CAPTION); diff --git a/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml b/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml index 92e0a65f8b..90db2afca7 100644 --- a/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml +++ b/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml @@ -15,7 +15,6 @@ IsMaximizable="False" IsMinimizable="False" IsResizable="False" - IsShownInSwitchers="False" IsTitleBarVisible="False" mc:Ignorable="d"> diff --git a/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs b/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs index dab53d9432..00db257bae 100644 --- a/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs +++ b/src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs @@ -305,7 +305,17 @@ public sealed partial class MainWindow : WindowEx, IDisposable return; } - _appWindow.IsShownInSwitchers = false; + try + { + _appWindow.IsShownInSwitchers = false; + } + catch (NotImplementedException) + { + // WinUI Will throw if explorer is not running, safely ignore + } + catch (Exception) + { + } } private bool CloakWindow()