diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 0bd6c7279cbc..ce6c08cb6698 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -1,6 +1,7 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. +using Microsoft.Extensions.Logging; using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml.Controls; @@ -247,11 +248,26 @@ async Task PerformNavigationAsync(string payload, string selectItem = null) } var generalSettingsService = Ioc.Default.GetService(); + + double boundsWidth = 0; + try + { + boundsWidth = Bounds.Width; + } + catch (Exception ex) + { + // Handle exception in case WinUI Windows is closed + // (see https://github.com/files-community/Files/issues/15599) + + App.Logger.LogWarning(ex, ex.Message); + return; + } + var paneNavigationArgs = new PaneNavigationArguments { LeftPaneNavPathParam = payload, LeftPaneSelectItemParam = selectItem, - RightPaneNavPathParam = Bounds.Width > Constants.UI.MultiplePaneWidthThreshold && (generalSettingsService?.AlwaysOpenDualPaneInNewTab ?? false) ? "Home" : null, + RightPaneNavPathParam = boundsWidth > Constants.UI.MultiplePaneWidthThreshold && (generalSettingsService?.AlwaysOpenDualPaneInNewTab ?? false) ? "Home" : null, }; if (rootFrame.Content is MainPage && MainPageViewModel.AppInstances.Any())