@@ -56,10 +56,10 @@ public abstract class BaseLayout : Page, INotifyPropertyChanged
56
56
57
57
public IShellPage ParentShellPageInstance { get ; private set ; } = null ;
58
58
59
- private bool isSearchResultPage = false ;
60
-
61
59
public bool IsRenamingItem { get ; set ; } = false ;
62
60
61
+ private NavigationArguments navigationArguments ;
62
+
63
63
private bool isItemSelected = false ;
64
64
65
65
public bool IsItemSelected
@@ -286,14 +286,21 @@ private void FolderSettings_LayoutModeChangeRequested(object sender, EventArgs e
286
286
{
287
287
var layoutType = FolderSettings . GetLayoutType ( ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ) ;
288
288
289
- ParentShellPageInstance . ContentFrame . Navigate ( layoutType , new NavigationArguments ( )
289
+ if ( layoutType != ParentShellPageInstance . CurrentPageType )
290
290
{
291
- NavPathParam = ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ,
292
- AssociatedTabInstance = ParentShellPageInstance
293
- } , null ) ;
291
+ ParentShellPageInstance . ContentFrame . Navigate ( layoutType , new NavigationArguments ( )
292
+ {
293
+ NavPathParam = navigationArguments . NavPathParam ,
294
+ IsSearchResultPage = navigationArguments . IsSearchResultPage ,
295
+ SearchPathParam = navigationArguments . SearchPathParam ,
296
+ SearchResults = navigationArguments . SearchResults ,
297
+ IsLayoutSwitch = true ,
298
+ AssociatedTabInstance = ParentShellPageInstance
299
+ } , null ) ;
294
300
295
- // Remove old layout from back stack
296
- ParentShellPageInstance . ContentFrame . BackStack . RemoveAt ( ParentShellPageInstance . ContentFrame . BackStack . Count - 1 ) ;
301
+ // Remove old layout from back stack
302
+ ParentShellPageInstance . ContentFrame . BackStack . RemoveAt ( ParentShellPageInstance . ContentFrame . BackStack . Count - 1 ) ;
303
+ }
297
304
}
298
305
}
299
306
@@ -309,24 +316,23 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
309
316
base . OnNavigatedTo ( eventArgs ) ;
310
317
// Add item jumping handler
311
318
Window . Current . CoreWindow . CharacterReceived += Page_CharacterReceived ;
312
- var parameters = ( NavigationArguments ) eventArgs . Parameter ;
313
- isSearchResultPage = parameters . IsSearchResultPage ;
314
- ParentShellPageInstance = parameters . AssociatedTabInstance ;
319
+ navigationArguments = ( NavigationArguments ) eventArgs . Parameter ;
320
+ ParentShellPageInstance = navigationArguments . AssociatedTabInstance ;
315
321
IsItemSelected = false ;
316
322
FolderSettings . LayoutModeChangeRequested += FolderSettings_LayoutModeChangeRequested ;
317
323
ParentShellPageInstance . FilesystemViewModel . IsFolderEmptyTextDisplayed = false ;
318
324
319
- if ( ! isSearchResultPage )
325
+ if ( ! navigationArguments . IsSearchResultPage )
320
326
{
321
327
ParentShellPageInstance . NavigationToolbar . CanRefresh = true ;
322
- ParentShellPageInstance . NavigationToolbar . CanCopyPathInPage = true ;
323
328
string previousDir = ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ;
324
- await ParentShellPageInstance . FilesystemViewModel . SetWorkingDirectoryAsync ( parameters . NavPathParam ) ;
329
+ await ParentShellPageInstance . FilesystemViewModel . SetWorkingDirectoryAsync ( navigationArguments . NavPathParam ) ;
325
330
326
331
// pathRoot will be empty on recycle bin path
327
332
var workingDir = ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ;
328
333
string pathRoot = Path . GetPathRoot ( workingDir ) ;
329
- if ( string . IsNullOrEmpty ( pathRoot ) || workingDir == pathRoot )
334
+ if ( string . IsNullOrEmpty ( pathRoot ) || workingDir == pathRoot
335
+ || workingDir . StartsWith ( AppSettings . RecycleBinPath ) ) // Can't go up from recycle bin
330
336
{
331
337
ParentShellPageInstance . NavigationToolbar . CanNavigateToParent = false ;
332
338
}
@@ -337,19 +343,30 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
337
343
338
344
ParentShellPageInstance . InstanceViewModel . IsPageTypeRecycleBin = workingDir . StartsWith ( App . AppSettings . RecycleBinPath ) ;
339
345
ParentShellPageInstance . InstanceViewModel . IsPageTypeMtpDevice = workingDir . StartsWith ( "\\ \\ ?\\ " ) ;
340
- ParentShellPageInstance . FilesystemViewModel . RefreshItems ( previousDir ) ;
341
- ParentShellPageInstance . NavigationToolbar . PathControlDisplayText = parameters . NavPathParam ;
342
346
ParentShellPageInstance . InstanceViewModel . IsPageTypeSearchResults = false ;
347
+ ParentShellPageInstance . NavigationToolbar . PathControlDisplayText = navigationArguments . NavPathParam ;
348
+ if ( ! navigationArguments . IsLayoutSwitch )
349
+ {
350
+ ParentShellPageInstance . FilesystemViewModel . RefreshItems ( previousDir ) ;
351
+ }
352
+ else
353
+ {
354
+ ParentShellPageInstance . NavigationToolbar . CanGoForward = false ;
355
+ }
343
356
}
344
357
else
345
358
{
346
359
ParentShellPageInstance . NavigationToolbar . CanRefresh = false ;
347
- ParentShellPageInstance . NavigationToolbar . CanCopyPathInPage = false ;
360
+ ParentShellPageInstance . NavigationToolbar . CanGoForward = false ;
361
+ ParentShellPageInstance . NavigationToolbar . CanGoBack = true ; // Impose no artificial restrictions on back navigation. Even in a search results page.
348
362
ParentShellPageInstance . NavigationToolbar . CanNavigateToParent = false ;
349
363
ParentShellPageInstance . InstanceViewModel . IsPageTypeRecycleBin = false ;
350
364
ParentShellPageInstance . InstanceViewModel . IsPageTypeMtpDevice = false ;
351
365
ParentShellPageInstance . InstanceViewModel . IsPageTypeSearchResults = true ;
352
- ParentShellPageInstance . FilesystemViewModel . AddSearchResultsToCollection ( parameters . SearchResults , parameters . SearchPathParam ) ;
366
+ if ( ! navigationArguments . IsLayoutSwitch )
367
+ {
368
+ ParentShellPageInstance . FilesystemViewModel . AddSearchResultsToCollection ( navigationArguments . SearchResults , navigationArguments . SearchPathParam ) ;
369
+ }
353
370
}
354
371
355
372
ParentShellPageInstance . InstanceViewModel . IsPageTypeNotHome = true ; // show controls that were hidden on the home page
@@ -364,12 +381,20 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
364
381
protected override void OnNavigatingFrom ( NavigatingCancelEventArgs e )
365
382
{
366
383
base . OnNavigatingFrom ( e ) ;
367
- ParentShellPageInstance . FilesystemViewModel . CancelLoadAndClearFiles ( isSearchResultPage ) ;
368
384
// Remove item jumping handler
369
385
Window . Current . CoreWindow . CharacterReceived -= Page_CharacterReceived ;
370
386
FolderSettings . LayoutModeChangeRequested -= FolderSettings_LayoutModeChangeRequested ;
371
387
}
372
388
389
+ protected override void OnNavigatedFrom ( NavigationEventArgs e )
390
+ {
391
+ var parameter = e . Parameter as NavigationArguments ;
392
+ if ( ! parameter . IsLayoutSwitch )
393
+ {
394
+ ParentShellPageInstance . FilesystemViewModel . CancelLoadAndClearFiles ( ) ;
395
+ }
396
+ }
397
+
373
398
private void UnloadMenuFlyoutItemByName ( string nameToUnload )
374
399
{
375
400
if ( FindName ( nameToUnload ) is MenuFlyoutItemBase menuItem ) // Prevent crash if the MenuFlyoutItem is missing
0 commit comments