Skip to content

Fix: Fixed issue where the app would crash when opening the properties window twice #14386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Files.App/Helpers/UI/DragZoneHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/Views/Properties/MainPropertiesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIElement, RectInt32?, RectInt32> getScaledRect)
Expand Down Expand Up @@ -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)
Expand All @@ -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<bool> SaveChangesAsync()
=> await Task.FromResult(false);

Expand Down