Skip to content
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

Fix: Fixed crash when switching to the List View layout #14533

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEven

private void RectangleSelection_PointerReleased(object sender, PointerRoutedEventArgs e)
{
if (scrollViewer is null) return;
Canvas.SetLeft(selectionRectangle, 0);
Canvas.SetTop(selectionRectangle, 0);
selectionRectangle.Width = 0;
Expand Down
22 changes: 11 additions & 11 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
</i:Interaction.Behaviors>

<local:BaseGroupableLayoutPage.Resources>
<ItemsPanelTemplate x:Key="VerticalItemsTemplate">
<ItemsWrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="HorizontalItemsTemplate">
<ItemsWrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
<Style x:Key="VerticalLayoutGridView" TargetType="GridView">
<Style.Setters>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate />
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
</Style.Setters>
</Style>

Expand All @@ -57,6 +57,10 @@
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
</Style.Setters>
</Style>

Expand Down Expand Up @@ -824,11 +828,7 @@
IsTabStop="True"
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
PreviewKeyDown="FileList_PreviewKeyDown"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Auto"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Auto"
SelectionChanged="FileList_SelectionChanged"
SelectionMode="Extended"
ShowsScrollingPlaceholders="True"
Expand Down
19 changes: 15 additions & 4 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,31 @@ private async void FolderSettings_LayoutModeChangeRequested(object? sender, Layo

private void SetItemTemplate()
{
switch (FolderSettings.LayoutMode)
var newFileListStyle = FolderSettings.LayoutMode switch
{
FolderLayoutModes.ListView => (Style)Resources["VerticalLayoutGridView"],
FolderLayoutModes.TilesView => (Style)Resources["HorizontalLayoutGridView"],
_ => (Style)Resources["HorizontalLayoutGridView"]
};

if (FileList.Style != newFileListStyle)
{
var oldSource = FileList.ItemsSource;
FileList.ItemsSource = null;
FileList.Style = newFileListStyle;
FileList.ItemsSource = oldSource;
}

switch (FolderSettings.LayoutMode)
{
case FolderLayoutModes.ListView:
FileList.ItemTemplate = ListViewBrowserTemplate;
FileList.ItemsPanel = (ItemsPanelTemplate)Resources["VerticalItemsTemplate"];
break;
case FolderLayoutModes.TilesView:
FileList.ItemTemplate = TilesBrowserTemplate;
FileList.ItemsPanel = (ItemsPanelTemplate)Resources["HorizontalItemsTemplate"];
break;
default:
FileList.ItemTemplate = GridViewBrowserTemplate;
FileList.ItemsPanel = (ItemsPanelTemplate)Resources["HorizontalItemsTemplate"];
break;
}

Expand Down