@@ -92,8 +92,7 @@ internal void ClearOpenedFolderSelectionIndicator()
9292 return ;
9393
9494 openedFolderPresenter . Background = new SolidColorBrush ( Microsoft . UI . Colors . Transparent ) ;
95- var presenter = openedFolderPresenter . FindDescendant < Grid > ( ) ! ;
96- presenter ! . Background = new SolidColorBrush ( Microsoft . UI . Colors . Transparent ) ;
95+ SetFolderBackground ( openedFolderPresenter , new SolidColorBrush ( Microsoft . UI . Colors . Transparent ) ) ;
9796 openedFolderPresenter = null ;
9897 }
9998
@@ -157,8 +156,8 @@ private void HighlightPathDirectory(ListViewBase sender, ContainerContentChangin
157156 if ( args . Item is ListedItem item && columnsOwner ? . OwnerPath is string ownerPath
158157 && ( ownerPath == item . ItemPath || ownerPath . StartsWith ( item . ItemPath ) && ownerPath [ item . ItemPath . Length ] is '/' or '\\ ' ) )
159158 {
160- var presenter = args . ItemContainer . FindDescendant < Grid > ( ) ! ;
161- presenter ! . Background = this . Resources [ "ListViewItemBackgroundSelected" ] as SolidColorBrush ;
159+ SetFolderBackground ( args . ItemContainer as ListViewItem , this . Resources [ "ListViewItemBackgroundSelected" ] as SolidColorBrush ) ;
160+
162161 openedFolderPresenter = FileList . ContainerFromItem ( item ) as ListViewItem ;
163162 FileList . ContainerContentChanging -= HighlightPathDirectory ;
164163 }
@@ -279,8 +278,7 @@ protected override void FileList_SelectionChanged(object sender, SelectionChange
279278
280279 if ( e . RemovedItems . Count > 0 && openedFolderPresenter != null )
281280 {
282- var presenter = openedFolderPresenter . FindDescendant < Grid > ( ) ! ;
283- presenter ! . Background = this . Resources [ "ListViewItemBackgroundSelected" ] as SolidColorBrush ;
281+ SetFolderBackground ( openedFolderPresenter , this . Resources [ "ListViewItemBackgroundSelected" ] as SolidColorBrush ) ;
284282 }
285283
286284 if ( SelectedItems ? . Count == 1 && SelectedItem ? . PrimaryItemAttribute is StorageItemTypes . Folder )
@@ -592,5 +590,16 @@ internal void ClearSelectionIndicator()
592590 FileList . SelectedItem = null ;
593591 LockPreviewPaneContent = false ;
594592 }
593+
594+ private static void SetFolderBackground ( ListViewItem ? lvi , SolidColorBrush ? backgroundColor )
595+ {
596+ if ( lvi == null || backgroundColor == null ) return ;
597+
598+
599+ if ( lvi . FindDescendant < Grid > ( ) is Grid presenter )
600+ {
601+ presenter . Background = backgroundColor ;
602+ }
603+ }
595604 }
596605}
0 commit comments