Skip to content

Fix: Fixed InvalidOperationException in ColumnsLayoutPage #14746

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

Merged
merged 1 commit into from
Feb 18, 2024
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
1 change: 0 additions & 1 deletion src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Windows.Storage;
using Windows.System;
using Windows.UI.Core;
using static Files.App.Constants;
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;

namespace Files.App.Views.Layouts
Expand Down
21 changes: 10 additions & 11 deletions src/Files.App/Views/Layouts/ColumnsLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Windows.Storage;
using static Files.App.Constants;
using static Files.App.Helpers.PathNormalization;

namespace Files.App.Views.Layouts
Expand Down Expand Up @@ -38,7 +37,7 @@ public ColumnsLayoutPage() : base()

public void HandleSelectionChange(ColumnLayoutPage initiator)
{
foreach (var blade in ColumnHost.ActiveBlades)
foreach (var blade in ColumnHost.ActiveBlades.ToList())
{
var columnView = blade.FindDescendant<ColumnLayoutPage>();
if (columnView != null && columnView != initiator)
Expand All @@ -64,7 +63,7 @@ private void ColumnViewBase_ItemInvoked(object? sender, EventArgs e)
return;

var nextBladeIndex = ColumnHost.ActiveBlades.IndexOf(column.ListView.FindAscendant<BladeItem>()) + 1;
var nextBlade = ColumnHost.ActiveBlades.ElementAtOrDefault(nextBladeIndex);
var nextBlade = ColumnHost.ActiveBlades.ToList().ElementAtOrDefault(nextBladeIndex);
var arePathsDifferent = ((nextBlade?.Content as Frame)?.Content as IShellPage)?.FilesystemViewModel?.WorkingDirectory != column.NavPathParam;

if (nextBlade is null || arePathsDifferent)
Expand Down Expand Up @@ -240,11 +239,11 @@ private void ColumnViewBrowser_GotFocus(object sender, RoutedEventArgs e)
if (sender is not IShellPage shPage || shPage.IsCurrentInstance)
return;

var currentBlade = ColumnHost.ActiveBlades.Single(x => (x.Content as Frame)?.Content == sender);
var currentBlade = ColumnHost.ActiveBlades.ToList().Single(x => (x.Content as Frame)?.Content == sender);
currentBlade.StartBringIntoView();
if (ColumnHost.ActiveBlades is not null)
{
ColumnHost.ActiveBlades.ForEach(x =>
ColumnHost.ActiveBlades.ToList().ForEach(x =>
{
var shellPage = (x.Content as Frame)?.Content as ColumnShellPage;
shellPage.IsCurrentInstance = false;
Expand Down Expand Up @@ -295,7 +294,7 @@ public void NavigateUp()
DismissOtherBlades(ColumnHost.ActiveBlades[ColumnHost.ActiveBlades.Count - 2]);
else
{
var workingDirectory = ((ColumnHost.ActiveBlades?.FirstOrDefault()?.Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
var workingDirectory = ((ColumnHost.ActiveBlades?.ToList().FirstOrDefault()?.Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
if (workingDirectory is null || string.Equals(workingDirectory, GetPathRoot(workingDirectory), StringComparison.OrdinalIgnoreCase))
ParentShellPageInstance?.NavigateHome();
else
Expand Down Expand Up @@ -358,8 +357,8 @@ public void SetSelectedPathOrNavigate(string navigationPath, Type sourcePageType
}

var destPath = navArgs is not null ? navArgs.NavPathParam : navigationPath;
var columnPath = ((ColumnHost.ActiveBlades.Last().Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
var columnFirstPath = ((ColumnHost.ActiveBlades.First().Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
var columnPath = ((ColumnHost.ActiveBlades.ToList().LastOrDefault()?.Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
var columnFirstPath = ((ColumnHost.ActiveBlades.ToList().FirstOrDefault()?.Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;

if (string.IsNullOrEmpty(destPath) || string.IsNullOrEmpty(columnPath) || string.IsNullOrEmpty(columnFirstPath))
{
Expand Down Expand Up @@ -403,7 +402,7 @@ public void SetSelectedPathOrNavigate(PathNavigationEventArgs e)
{
if (ColumnHost.ActiveBlades?.Count > 1)
{
foreach (var item in ColumnHost.ActiveBlades)
foreach (var item in ColumnHost.ActiveBlades.ToList())
{
if ((item.Content as Frame)?.Content is ColumnShellPage s &&
NormalizePath(s.FilesystemViewModel?.WorkingDirectory) == NormalizePath(e.ItemPath))
Expand All @@ -429,7 +428,7 @@ public IShellPage ActiveColumnShellPage
{
if (ColumnHost.ActiveBlades?.Count > 0)
{
var shellPages = ColumnHost.ActiveBlades.Select(x => (x.Content as Frame).Content as IShellPage);
var shellPages = ColumnHost.ActiveBlades.ToList().Select(x => (x.Content as Frame).Content as IShellPage);
var activeInstance = shellPages.SingleOrDefault(x => x.IsCurrentInstance);
return activeInstance ?? shellPages.Last();
}
Expand Down Expand Up @@ -467,7 +466,7 @@ private void CloseUnnecessaryColumns(ColumnParam column)
if (relativeIndex is -1)
{
// Get the index of the blade with the same path as the requested
var blade = ColumnHost.ActiveBlades.FirstOrDefault(b =>
var blade = ColumnHost.ActiveBlades.ToList().FirstOrDefault(b =>
column.NavPathParam.Equals(((b.Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel?.WorkingDirectory));

if (blade is not null)
Expand Down