public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null)
{
// Don't open the same page multiple times
if (Frame.Content?.GetType() != pageType)
{
return Frame.Navigate(pageType, parameter, infoOverride);
}
else
{
return false;
}
}
This is the Navigate method in the project I created, as the comment says Dont open the same page multiple times, I think it should have an optional parameter in the method to override this behaviour, because there are many scenarios, where it is suitable for the user to navigate front and back to the same page, an example of that scenario is the FileExplorer navigation, where the user drills in and out of the folder by clicking them, and back button should take them to a level up in the tree, but this behaviour is currently not possible because of this Dont open same page multiple times feature.
WTS details for my project
<genTemplate:Metadata>
<genTemplate:Item Name="generator" Value="Windows Template Studio" />
<genTemplate:Item Name="wizardVersion" Version="v0.17.18080.1" />
<genTemplate:Item Name="templatesVersion" Version="v0.17.18080.1" />
<genTemplate:Item Name="projectType" Value="SplitView" />
<genTemplate:Item Name="framework" Value="MVVMBasic" />
</genTemplate:Metadata>
The navigation service was created for use with the Navigation Pane / Hamburger model.
With the code we generate for projects of this type, the expectation is that the majority of navigation will be triggered through the menu at the side of the shell. When navigating this way, if you click/tap the entry for the page that is currently displayed in the main display area of the app it should not navigate to the same page again. This is the incorrect behavior that the NavigationService tries to prevent.
When using a very different navigation model within an app, the 'Blank' project type may be more appropriate and that allows you to handle navigation in whatever way is best for the app.
From the example of a FileExplorer, I'm not sure that navigation between pages is something I'd necessarily use to show the contents of different directories. Without seeing the specific code or understanding the reason for it I couldn't comment further.
However, there are cases where this current behavior doesn't always make sense (@JohnnyWestlake has some good examples in the linked toolkit issue) and so the default functionality should be reconsidered.
There's a really simple way to remove this functionality from the generated project if it doesn't apply. Just delete the code that does the check.
In reality, the check is useful in some cases but inadequate and limiting in others.
I do not believe that some sort of configurable behavior is the way to go with changing this. It adds complexity to the code and requires more from the developer calling the code.
Instead, I propose that the check is extended to make sure that navigation to the same page and passing the same parameter should be prevented and navigation to the same page but with a different parameter passed should be allowed.
I've used this technique many times elsewhere.
Does anyone have an alternative approach to suggest instead, or see any limitations with adding the parameter check?
@mrlacey yes this is exactly what I am suggesting as well, the default behaviour right now is good, but if the developer has a specific usecase and wants to Navigate to the same page then they can override this functionality with an extra optional parameter AllowNavigationToSamePage, which will be false by default in the NavigationService.Navigate(...,bool AllowNavigationToSamePage=false) but if user provides a true ( when calling this method ) then this fucntionality will change and navigation to same page will be allowed.
yes this is exactly what I am suggesting as well
No. You're suggesting something that contradicts my statement: "I do not believe that some sort of configurable behavior is the way to go with changing this. It adds complexity to the code and requires more from the developer calling the code."
I'm suggesting changing it to something like:
if (Frame.Content?.GetType() != pageType && parameter != lastParamUsed)
{
return Frame.Navigate(pageType, parameter, infoOverride);
}
oh ok I get it now, yeah tht is also a good way to achieve this.
Navigation services updated on #2177 on templates (MVVMBasic, MVVMLight, CodeBehind) C# and VB.
Verified in dev-nightly:
Templates version: 0.18.18110.2
Wizard version: 0.18.18110.2