Skip to content

Commit 034759f

Browse files
shuaiyuanxxvanzue
andcommitted
Fix WinuiEx crash issue (#45443)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## 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. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [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 <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: vanzue <vanzue@outlook.com>
1 parent 934c3bb commit 034759f

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
IsMaximizable="False"
1111
IsMinimizable="False"
1212
IsResizable="False"
13-
IsShownInSwitchers="False"
1413
IsTitleBarVisible="False"
1514
mc:Ignorable="d">
1615
<winuiex:WindowEx.Backdrop>

src/modules/MeasureTool/MeasureToolUI/MeasureToolXAML/MainWindow.xaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,23 @@ public MainWindow(PowerToys.MeasureToolCore.Core core)
5252
var presenter = _appWindow.Presenter as OverlappedPresenter;
5353
presenter.IsAlwaysOnTop = true;
5454
this.SetIsAlwaysOnTop(true);
55-
this.SetIsShownInSwitchers(false);
5655
this.SetIsResizable(false);
5756
this.SetIsMinimizable(false);
5857
this.SetIsMaximizable(false);
5958
IsTitleBarVisible = false;
6059

60+
try
61+
{
62+
this.SetIsShownInSwitchers(false);
63+
}
64+
catch (NotImplementedException)
65+
{
66+
// WinUI will throw if explorer is not running, safely ignore
67+
}
68+
catch (Exception)
69+
{
70+
}
71+
6172
// 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.
6273
var windowStyle = GetWindowLong(hwnd, GWL_STYLE);
6374
windowStyle = windowStyle & (~WS_CAPTION);

src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
IsMaximizable="False"
1616
IsMinimizable="False"
1717
IsResizable="False"
18-
IsShownInSwitchers="False"
1918
IsTitleBarVisible="False"
2019
mc:Ignorable="d">
2120
<winuiEx:WindowEx.Backdrop>

src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,17 @@ private void HideFromTaskbar()
305305
return;
306306
}
307307

308-
_appWindow.IsShownInSwitchers = false;
308+
try
309+
{
310+
_appWindow.IsShownInSwitchers = false;
311+
}
312+
catch (NotImplementedException)
313+
{
314+
// WinUI Will throw if explorer is not running, safely ignore
315+
}
316+
catch (Exception)
317+
{
318+
}
309319
}
310320

311321
private bool CloakWindow()

0 commit comments

Comments
 (0)