Skip to content

Commit 71742c3

Browse files
authored
Fix: Fixed NullReferenceException when renaming files (files-community#14350)
1 parent fa2caab commit 71742c3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,27 @@ protected override void EndRename(TextBox textBox)
253253
{
254254
Popup? popup = gridViewItem.FindDescendant("EditPopup") as Popup;
255255
TextBlock? textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock;
256-
popup!.IsOpen = false;
257-
textBlock!.Opacity = (textBlock.DataContext as ListedItem)!.Opacity;
256+
257+
if (popup is not null)
258+
popup.IsOpen = false;
259+
260+
if (textBlock is not null)
261+
textBlock.Opacity = (textBlock.DataContext as ListedItem)!.Opacity;
258262
}
259263
else if (FolderSettings.LayoutMode == FolderLayoutModes.TilesView)
260264
{
261265
TextBlock? textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock;
266+
262267
textBox.Visibility = Visibility.Collapsed;
263-
textBlock!.Visibility = Visibility.Visible;
268+
269+
if (textBlock is not null)
270+
textBlock.Visibility = Visibility.Visible;
264271
}
265272

266273
// Unsubscribe from events
267274
if (textBox is not null)
268275
{
269-
textBox!.LostFocus -= RenameTextBox_LostFocus;
276+
textBox.LostFocus -= RenameTextBox_LostFocus;
270277
textBox.KeyDown -= RenameTextBox_KeyDown;
271278
}
272279

@@ -430,15 +437,17 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e)
430437
if (FolderSettings.LayoutMode == FolderLayoutModes.GridView)
431438
{
432439
Popup popup = gridViewItem.FindDescendant("EditPopup") as Popup;
433-
var textBox = popup.Child as TextBox;
440+
var textBox = popup?.Child as TextBox;
434441

435-
await CommitRenameAsync(textBox);
442+
if (textBox is not null)
443+
await CommitRenameAsync(textBox);
436444
}
437445
else
438446
{
439447
var textBox = gridViewItem.FindDescendant("TileViewTextBoxItemName") as TextBox;
440448

441-
await CommitRenameAsync(textBox);
449+
if (textBox is not null)
450+
await CommitRenameAsync(textBox);
442451
}
443452
}
444453
}

0 commit comments

Comments
 (0)