Skip to content

Commit a1d0bc7

Browse files
authored
Fix: Fixed issue where the app would crash when opening the properties window twice (#14386)
1 parent 35cc6ad commit a1d0bc7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Files.App/Helpers/UI/DragZoneHelper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ public static void RaiseSetTitleBarDragRegion(this Window window, SetTitleBarDra
2525
// UIElement.RasterizationScale is always 1
2626
var source = InputNonClientPointerSource.GetForWindowId(window.AppWindow.Id);
2727
var uiElement = window.Content;
28-
var scaleFactor = uiElement.XamlRoot.RasterizationScale;
28+
var xamlRoot = uiElement?.XamlRoot;
29+
30+
if (xamlRoot is null)
31+
return;
32+
33+
var scaleFactor = xamlRoot.RasterizationScale;
2934
var size = window.AppWindow.Size;
3035
// 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
3136
source.ClearRegionRects(NonClientRegionKind.Passthrough);

src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
5252

5353
UpdatePageLayout();
5454
Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
55-
Window.AppWindow.Changed += (_, _) => Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
55+
Window.AppWindow.Changed += AppWindow_Changed;
5656
}
5757

5858
private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
@@ -116,6 +116,7 @@ private void Window_Closed(object sender, WindowEventArgs args)
116116
{
117117
AppSettings.ThemeModeChanged -= AppSettings_ThemeModeChanged;
118118
Window.Closed -= Window_Closed;
119+
Window.AppWindow.Changed -= AppWindow_Changed;
119120

120121
if (MainPropertiesViewModel.ChangedPropertiesCancellationTokenSource is not null &&
121122
!MainPropertiesViewModel.ChangedPropertiesCancellationTokenSource.IsCancellationRequested)
@@ -124,6 +125,11 @@ private void Window_Closed(object sender, WindowEventArgs args)
124125
}
125126
}
126127

128+
private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs e)
129+
{
130+
Window.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
131+
}
132+
127133
public override async Task<bool> SaveChangesAsync()
128134
=> await Task.FromResult(false);
129135

0 commit comments

Comments
 (0)