diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs index 258f23f16506..47a1aab05eff 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs @@ -253,20 +253,27 @@ protected override void EndRename(TextBox textBox) { Popup? popup = gridViewItem.FindDescendant("EditPopup") as Popup; TextBlock? textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock; - popup!.IsOpen = false; - textBlock!.Opacity = (textBlock.DataContext as ListedItem)!.Opacity; + + if (popup is not null) + popup.IsOpen = false; + + if (textBlock is not null) + textBlock.Opacity = (textBlock.DataContext as ListedItem)!.Opacity; } else if (FolderSettings.LayoutMode == FolderLayoutModes.TilesView) { TextBlock? textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock; + textBox.Visibility = Visibility.Collapsed; - textBlock!.Visibility = Visibility.Visible; + + if (textBlock is not null) + textBlock.Visibility = Visibility.Visible; } // Unsubscribe from events if (textBox is not null) { - textBox!.LostFocus -= RenameTextBox_LostFocus; + textBox.LostFocus -= RenameTextBox_LostFocus; textBox.KeyDown -= RenameTextBox_KeyDown; } @@ -430,15 +437,17 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e) if (FolderSettings.LayoutMode == FolderLayoutModes.GridView) { Popup popup = gridViewItem.FindDescendant("EditPopup") as Popup; - var textBox = popup.Child as TextBox; + var textBox = popup?.Child as TextBox; - await CommitRenameAsync(textBox); + if (textBox is not null) + await CommitRenameAsync(textBox); } else { var textBox = gridViewItem.FindDescendant("TileViewTextBoxItemName") as TextBox; - await CommitRenameAsync(textBox); + if (textBox is not null) + await CommitRenameAsync(textBox); } } }