diff --git a/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml b/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml index 90b316dfb816..aa109bf5a3a6 100644 --- a/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml @@ -191,6 +191,7 @@ IsRightTapEnabled="True" IsTabStop="True" ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}" + Loaded="FileList_Loaded" PreviewKeyDown="FileList_PreviewKeyDown" RightTapped="FileList_RightTapped" ScrollViewer.IsScrollInertiaEnabled="True" diff --git a/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs index 375d85f968c1..bf9017d4f5a2 100644 --- a/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs @@ -40,7 +40,7 @@ public sealed partial class ColumnLayoutPage : BaseGroupableLayoutPage protected override ListViewBase ListViewBase => FileList; protected override SemanticZoom RootZoom => RootGridZoom; - + public ScrollViewer? ContentScroller { get; private set; } /// /// Row height in the Columns View @@ -66,6 +66,11 @@ public ColumnLayoutPage() : base() // Methods + private void FileList_Loaded(object sender, RoutedEventArgs e) + { + ContentScroller = FileList.FindDescendant(x => x.Name == "ScrollViewer"); + } + private void ColumnViewBase_GotFocus(object sender, RoutedEventArgs e) { if (FileList.SelectedItem == null && openedFolderPresenter != null) @@ -167,14 +172,18 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - // TODO keep scroll position when changing styles (see details view) - if (e.PropertyName == nameof(ILayoutSettingsService.ColumnsViewSize)) { + // Get current scroll position + var previousOffset = ContentScroller?.VerticalOffset; + NotifyPropertyChanged(nameof(RowHeight)); // Update the container style to match the item size SetItemContainerStyle(); + + // Restore correct scroll position + ContentScroller?.ChangeView(null, previousOffset, null); } } diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml b/src/Files.App/Views/Layouts/GridLayoutPage.xaml index ee4504ed33c0..d83ba1b65ac5 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml @@ -778,6 +778,7 @@ IsTabStop="True" ItemContainerTransitions="{x:Null}" ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}" + Loaded="FileList_Loaded" PreviewKeyDown="FileList_PreviewKeyDown" ScrollViewer.IsHorizontalScrollChainingEnabled="False" SelectionChanged="FileList_SelectionChanged" diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs index 925cec771922..060908c43c47 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs @@ -28,6 +28,8 @@ public sealed partial class GridLayoutPage : BaseGroupableLayoutPage // Properties + public ScrollViewer? ContentScroller { get; private set; } + protected override ListViewBase ListViewBase => FileList; protected override SemanticZoom RootZoom => RootGridZoom; @@ -147,7 +149,10 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e) { - // TODO keep scroll position when changing styles (see details view) + // Get current scroll position + // Get current scroll position + var previousHorizontalOffset = ContentScroller?.HorizontalOffset; + var previousVerticalOffset = ContentScroller?.VerticalOffset; if (e.PropertyName == nameof(ILayoutSettingsService.ListViewSize)) { @@ -175,6 +180,9 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang FolderSettings_IconHeightChanged(); } + + // Restore correct scroll position + ContentScroller?.ChangeView(previousHorizontalOffset, previousVerticalOffset, null); } private async void FolderSettings_LayoutModeChangeRequested(object? sender, LayoutModeEventArgs e) @@ -249,6 +257,11 @@ private void SetItemContainerStyle() } } + private void FileList_Loaded(object sender, RoutedEventArgs e) + { + ContentScroller = FileList.FindDescendant(x => x.Name == "ScrollViewer"); + } + protected override void FileList_SelectionChanged(object sender, SelectionChangedEventArgs e) { base.FileList_SelectionChanged(sender, e);