@@ -28,7 +28,7 @@ public class SidebarPinnedModel
2828
2929 private SidebarPinnedController controller ;
3030
31- private LocationItem favoriteSection , homeSection ;
31+ private LocationItem favoriteSection ;
3232
3333 [ JsonIgnore ]
3434 public MainViewModel MainViewModel => App . MainViewModel ;
@@ -43,6 +43,7 @@ public void SetController(SidebarPinnedController controller)
4343
4444 public SidebarPinnedModel ( )
4545 {
46+ favoriteSection = SidebarControl . SideBarItems . FirstOrDefault ( x => x . Text == "SidebarFavorites" . GetLocalized ( ) ) as LocationItem ;
4647 }
4748
4849 /// <summary>
@@ -282,7 +283,7 @@ public async Task AddItemToSidebarAsync(string path)
282283 }
283284 }
284285
285- if ( ! favoriteSection . ChildItems . Contains ( locationItem ) )
286+ if ( ! favoriteSection . ChildItems . Any ( x => x . Path == locationItem . Path ) )
286287 {
287288 await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) => favoriteSection . ChildItems . Insert ( insertIndex , locationItem ) ) ;
288289 }
@@ -303,7 +304,7 @@ private void AddItemToSidebarAsync(LocationItem section)
303304 var lastItem = favoriteSection . ChildItems . LastOrDefault ( x => x . ItemType == NavigationControlItemType . Location && ! x . Path . Equals ( CommonPaths . RecycleBinPath ) ) ;
304305 int insertIndex = lastItem != null ? favoriteSection . ChildItems . IndexOf ( lastItem ) + 1 : 0 ;
305306
306- if ( ! favoriteSection . ChildItems . Contains ( section ) )
307+ if ( ! favoriteSection . ChildItems . Any ( x => x . Section == section . Section ) )
307308 {
308309 favoriteSection . ChildItems . Insert ( insertIndex , section ) ;
309310 }
@@ -322,7 +323,7 @@ public async Task AddAllItemsToSidebar()
322323 await SidebarControl . SideBarItemsSemaphore . WaitAsync ( ) ;
323324 try
324325 {
325- homeSection = new LocationItem ( )
326+ var homeSection = new LocationItem ( )
326327 {
327328 Text = "SidebarHome" . GetLocalized ( ) ,
328329 Section = SectionType . Home ,
@@ -332,7 +333,7 @@ public async Task AddAllItemsToSidebar()
332333 Path = "Home" . GetLocalized ( ) ,
333334 ChildItems = new ObservableCollection < INavigationControlItem > ( )
334335 } ;
335- favoriteSection = new LocationItem ( )
336+ favoriteSection ?? = new LocationItem ( )
336337 {
337338 Text = "SidebarFavorites" . GetLocalized ( ) ,
338339 Section = SectionType . Favorites ,
@@ -347,7 +348,7 @@ public async Task AddAllItemsToSidebar()
347348 AddItemToSidebarAsync ( homeSection ) ;
348349 }
349350
350- if ( ! SidebarControl . SideBarItems . Contains ( favoriteSection ) )
351+ if ( ! SidebarControl . SideBarItems . Any ( x => x . Text == "SidebarFavorites" . GetLocalized ( ) ) )
351352 {
352353 SidebarControl . SideBarItems . BeginBulkOperation ( ) ;
353354 var index = 0 ; // First section
0 commit comments