diff --git a/src/Files.App/Views/Layouts/BaseLayoutPage.cs b/src/Files.App/Views/Layouts/BaseLayoutPage.cs index 83fcb600934d..a11f1d72cb42 100644 --- a/src/Files.App/Views/Layouts/BaseLayoutPage.cs +++ b/src/Files.App/Views/Layouts/BaseLayoutPage.cs @@ -958,7 +958,7 @@ protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceive } } - protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e) + protected virtual void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { try { @@ -1094,7 +1094,7 @@ private async void Item_DragOver(object sender, DragEventArgs e) } } - private async void Item_Drop(object sender, DragEventArgs e) + protected virtual async void Item_Drop(object sender, DragEventArgs e) { var deferral = e.GetDeferral(); @@ -1282,7 +1282,7 @@ protected void ItemsLayout_DragOver(object sender, DragEventArgs e) CommandsViewModel?.DragOverCommand?.Execute(e); } - protected void ItemsLayout_Drop(object sender, DragEventArgs e) + protected virtual void ItemsLayout_Drop(object sender, DragEventArgs e) { CommandsViewModel?.DropCommand?.Execute(e); } diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml b/src/Files.App/Views/Layouts/GridLayoutPage.xaml index f5adce4f7863..1c10777f4d50 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml @@ -819,7 +819,9 @@ CanDragItems="{x:Bind AllowItemDrag, Mode=OneWay}" ContainerContentChanging="FileList_ContainerContentChanging" DoubleTapped="FileList_DoubleTapped" + DragEnter="ItemsLayout_DragEnter" DragItemsStarting="FileList_DragItemsStarting" + DragLeave="ItemsLayout_DragLeave" DragOver="ItemsLayout_DragOver" Drop="ItemsLayout_Drop" FocusVisualPrimaryThickness="0" diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs index 3104c6e4ed73..e9d351fb4271 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs @@ -639,6 +639,47 @@ private void SelectionCheckbox_PointerCanceled(object sender, PointerRoutedEvent UpdateCheckboxVisibility((sender as FrameworkElement)!.FindAscendant()!, false); } + // To avoid crashes, disable scrolling when drag-and-drop if grouped. (#14484) + protected override void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e) + { + if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); + + base.FileList_DragItemsStarting(sender, e); + + if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false && + e.Cancel) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + } + + private void ItemsLayout_DragEnter(object sender, DragEventArgs e) + { + if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); + } + + private void ItemsLayout_DragLeave(object sender, DragEventArgs e) + { + if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + } + + protected override void ItemsLayout_Drop(object sender, DragEventArgs e) + { + if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + + base.ItemsLayout_Drop(sender, e); + } + + protected override void Item_Drop(object sender, DragEventArgs e) + { + if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + + base.Item_Drop(sender, e); + } + private void UpdateCheckboxVisibility(object sender, bool isPointerOver) { if (sender is GridViewItem control && control.FindDescendant() is UserControl userControl)