diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml b/src/Files.App/Views/Layouts/GridLayoutPage.xaml index 5df80a4c0875..7ba67452df65 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml @@ -13,7 +13,6 @@ xmlns:local="using:Files.App.Views.Layouts" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:storage="using:Files.App.Utils.Storage" - xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls" xmlns:tui="using:CommunityToolkit.WinUI.UI" xmlns:uc="using:Files.App.UserControls" xmlns:wctanimations="using:CommunityToolkit.WinUI.UI.Animations" @@ -41,7 +40,8 @@ - + + diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs index bd217e3e1a82..acd6a88c78d9 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs @@ -24,6 +24,7 @@ public sealed partial class GridLayoutPage : BaseGroupableLayoutPage // Fields private uint currentIconSize; + private volatile bool shouldSetVerticalScrollMode; // Properties @@ -238,6 +239,8 @@ private void SetItemTemplate() FileList.ItemsSource = oldSource; } + shouldSetVerticalScrollMode = true; + switch (FolderSettings.LayoutMode) { case FolderLayoutModes.ListView: @@ -664,6 +667,17 @@ private void Grid_Loaded(object sender, RoutedEventArgs e) if (item is GridViewItem itemContainer) itemContainer.ContextFlyout = ItemContextMenuFlyout; + + // Set VerticalScrollMode after an item has been loaded (#14785) + if (shouldSetVerticalScrollMode) + { + shouldSetVerticalScrollMode = false; + + if (FolderSettings?.LayoutMode is FolderLayoutModes.ListView) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); + else + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); + } } private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e) @@ -689,42 +703,45 @@ private void SelectionCheckbox_PointerCanceled(object sender, PointerRoutedEvent } // To avoid crashes, disable scrolling when drag-and-drop if grouped. (#14484) + private bool ShouldDisableScrollingWhenDragAndDrop => + FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false); + protected override void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); base.FileList_DragItemsStarting(sender, e); - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false && - e.Cancel) - ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + if (ShouldDisableScrollingWhenDragAndDrop && e.Cancel) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); } private void ItemsLayout_DragEnter(object sender, DragEventArgs e) { - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); } private void ItemsLayout_DragLeave(object sender, DragEventArgs e) { - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) - ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + if (ShouldDisableScrollingWhenDragAndDrop) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); } protected override void ItemsLayout_Drop(object sender, DragEventArgs e) { - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) - ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + if (ShouldDisableScrollingWhenDragAndDrop) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); 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); + if (ShouldDisableScrollingWhenDragAndDrop) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); base.Item_Drop(sender, e); }