From a437597566dd2cc43268c4a8b64cc3c8eb894a26 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Tue, 9 Jan 2024 00:49:36 +0900 Subject: [PATCH] Fixed crash --- src/Files.App/Helpers/UI/DragZoneHelper.cs | 7 ++++++- src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Helpers/UI/DragZoneHelper.cs b/src/Files.App/Helpers/UI/DragZoneHelper.cs index 17b7de41cce0..da2e557ab43f 100644 --- a/src/Files.App/Helpers/UI/DragZoneHelper.cs +++ b/src/Files.App/Helpers/UI/DragZoneHelper.cs @@ -25,7 +25,12 @@ public static void RaiseSetTitleBarDragRegion(this Window window, SetTitleBarDra // UIElement.RasterizationScale is always 1 var source = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id); var uiElement = window.Content; - var scaleFactor = uiElement.XamlRoot.RasterizationScale; + var xamlRoot = uiElement?.XamlRoot; + + if (xamlRoot is null) + return; + + var scaleFactor = xamlRoot.RasterizationScale; var size = window.AppWindow.Size; // If the number of regions is 0 or 1, AppWindow will automatically reset to the default region next time, but if it is >=2, it will not and need to be manually cleared source.ClearRegionRects(NonClientRegionKind.Passthrough); diff --git a/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs b/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs index ffa59512b238..f62a3b7863da 100644 --- a/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs +++ b/src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs @@ -52,7 +52,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e) UpdatePageLayout(); Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion); - Window.AppWindow.Changed += (_, _) => Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion); + Window.AppWindow.Changed += AppWindow_Changed; } private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func getScaledRect) @@ -116,6 +116,7 @@ private void Window_Closed(object sender, WindowEventArgs args) { AppSettings.ThemeModeChanged -= AppSettings_ThemeModeChanged; Window.Closed -= Window_Closed; + Window.AppWindow.Changed -= AppWindow_Changed; if (MainPropertiesViewModel.ChangedPropertiesCancellationTokenSource is not null && !MainPropertiesViewModel.ChangedPropertiesCancellationTokenSource.IsCancellationRequested) @@ -124,6 +125,11 @@ private void Window_Closed(object sender, WindowEventArgs args) } } + private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs e) + { + Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion); + } + public override async Task SaveChangesAsync() => await Task.FromResult(false);