Skip to content

Commit

Permalink
Fix: Fixed crash when switching to the List View layout (files-commun…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelwgn authored Jan 23, 2024
1 parent 7f9d085 commit 407d1fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
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

0 comments on commit 407d1fd

Please sign in to comment.