Windowstemplatestudio: Docs: Activation for nav pane and directly going to a page

Created on 20 Jun 2017  路  18Comments  路  Source: microsoft/WindowsTemplateStudio

From #456, a user was interested in having his app go directly to a page, not using ShellPage.

We should provide guidance on

  • directly going to that page VS using shell page
  • warn of any issues this could cause
  • how to move back to shell page if the user clicks a button or something to go back to the main page
Can Close Out Soon Documentation help wanted

All 18 comments

feel like https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md or a subpage for this should be where this lives

well I havent really tried to add the functionality of going back to the mainpage yet, because specs of my app are not yet decided about that feature. But for now I can tell how to navigate to another page by skipping the ShellPage which is pretty simple and straightforward.

  1. Comment out the OnActivated method within "App.xaml.cs"
  2. override OnFileActivated method within "App.xaml.cs".
  3. and within method OnFileActivated just navigate to the required page.

Side Effects
No activation service is created for the App because that is normally handled in OnLaunched method.

Code

` //protected override async void OnActivated(IActivatedEventArgs args)
//{
// await ActivationService.ActivateAsync(args);
//}

    protected override void OnFileActivated(FileActivatedEventArgs args)
    {
        if (args.Files.Count > 0)
        {
            Type TargetType = typeof(CompactNowPlayingPage);

            var SingleFileToPlay = args.Files[0] as StorageFile;
            TargetType = typeof(CompactNowPlayingPage);

            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            rootFrame.Navigate(TargetType, SingleFileToPlay);

            Window.Current.Activate();
        }
    }`

To simply navigate back to the ShellPage, just try following on the target page.
this.Frame.Navigate(typeof(ShellPage)); // without the activation service support though.

I will try including the activation service with it and will update you guyx if I am successful in achieving that.

I'd love to see this addressed. The ShellPage seems weird to me. It's the default landing page yet it can't be accessed from the hamburger. I'd like the a bility to just have the app start on MainPage yet still inherit the nav stuff from ShellPage.

It feels as if it may have been better to add the Navigation Panel by overriding the styling of the default frame. This would have avoided the confusion of ShellPage being an actual Page. Such a change is too big to consider right now (for 1.2), but we do need a simple documented way to display a page without app wide chrome (which is basically what the nav menu is.)
This also applies to apps using tabs for top level nav, as may have reason to hide that on some occasions too.

@EricAtMSFT great feedback. To do your adjustment, i few that as a new issue outside the primary issue. If this is something you feel strongly on, lets please open a new issue.

i agree with @mrlacey that this is a larger change for 1.2 and what the preferred pattern would be for Navigation View for FCU and future work with that control.

I think we should really think about this and what is the best way as this should also be under consideration for Xamarin support.

@EricAtMSFT I'd like to understand a bit more about your scenario. The Shellpage is really just a container for the Navigation/Hamburger menu. It doesn't have any content and so I don't understand what you'd want from being able to navigate to it from the menu. If this existed you'd just end up with nav menu inside nav menu, potentially indefinitely.

The ability to navigate to a new page without any of the app's standard navigation chrome is something I've needed in many apps in the past. We should have picked up this need earlier. This may be needed at startup (e.g. sign-in pages) or from within the app (e.g. open an embedded browser or video player "full screen").

Here's my thinking for this:

  1. Add docs to show a workaround for a short term fix.
  2. Create a new issue for having the ability to navigate without the "shell" built into the generated code as a long term solution.

@mrlacey For me, the ShellPage is an odd choice as the "MainPage" for this template, especially given that it's not even part of the hamburger.

I just want the app to start at one of the other pages I have created, that's included in the hamburger menu but I haven't been able to make that work.

TLDR. I'm open to either #1 or #2 mentioned above.

Thanks!

@EricAtMSFT If you just want to have the app open with a different page (other than the first in the list) simply change the View type reference in App.xaml.cs. So, in the below, MainPage could be changed to whatever you want.

private ActivationService CreateActivationService()
{
    return new ActivationService(this, typeof(Views.MainPage), new Views.ShellPage());
}

If you want it without the menu visible then you'll need to wait for #697

I'm working on a PoC that use a most advanced NavigationService to reach more complex scenarios with a great usability.
The target on this is PoC is to add these changes to the documentation to give to experienced developers to reach more complex scenarios.

The code can be checked out here.

@mvegaca I think this is perfect way of doing it :)

PoC Updated to reach complex navigation scenarios. If someone has some comments on this PoC it could help me to improve the navigation system or reach scenarios in which I haven't thought.

AdvancedNavigationPaneProject.

Hi @mrlacey @dgomezc
Can you look at the AdvancedNavigation PoC App paying attention to the NavigationService, I'm sure that it would be a great feature that adds navigation classes to advanced developers that want reach more advanced scenarios.

Thanks guys

@mvegaca
I'm not clear on what all the scenarios are that this is supposed to cover. Are they listed somewhere? I don't really want to comment on what you've done without understanding _everything_ that it's supposed to do.

The NavigationService and additional new files/classes it uses add a lot of unnecessary complexity if someone doesn't want anything other than the current functionality. Is this POC being proposed as a replacement for the current NavigationService, an optional alternative, or something else? This seems like a lot to add if it's not needed and I'd like to avoid adding it only because it might be needed in the future or when adding other pages/features (via right-click.)

Look like bugs:

  • Click to Start > Map > Map displayed but no back button! (running on FCU)
  • Theme selection (if changed in settings) is not remembered after changing frames within the app.

Some comments on the code that is there:

NavigationService.Navigate has a lot of overloads and it isn't immediately clear what they're all for. Some comments here woudl be helpful.

Classes ending "Ex" are normally extended versions of the class they are an extension of. PageStackEntryEx is very different from PageStackEntry and NavigationEventArgsEx is very different from NavigationEventArgs. The names you've used are potentially confusing and alternate names should be used.

NavigationEventArgsEx should inherit from EventArgs as all classes used for event arguments should.

NavigationConfig contains constructors that aren't used. Are they all necessary? Some documentation/comments here might help too.

Thanks Matt for you feedback.
The intention on that is not to replace the current NavigationService, is to add a documentation to explain how to create a more complex NavigationService for advanced navigation scenarios like:

  • A StartUp page on application launching that Navigates to a ShellPage without back navigation.
  • A ShellPage that adds a second frame to the navigation model. You can navigate between Main, Map and Settings page without the possibility to come back using the back button.

    • Map page adds a button to see on full screen using the main frame navigation.

    • WebView button opens a WebView page in the main frame.

    • LogOut restores all the navigation system and returns to the StartUp Page.

    • SecondShell button on MainPage navigate in the main frame to a new second shell Scenario. This Second Shell adds a third frame to the navigation model. You can navigate between Main and Other page with the possibility come back using the back button.

By this moment the main idea is to create a documentation to explain how to integrate that in an exisitng project, in the future we can study to add this NavigationModel in a new feature or in a new project type.

I've fixed the NavigationServices classes names and the theme selection in Frame. The next steps is to create the documentation explaining the code in the documentation and adding documentation also in code.

I agre with @mvegaca his work is definitely helpful as far as docs are concerned and I also agree with @mrlacey that this should not replace NavigationService. as we dont wanna put extra complications to the app unless they are required. as these advanced scenarios are very specific and custom its best to have them in docs or maybe in the wizard as an advanced option? where the developer can check "advanced navigation" and they will be advised that it supports following 4,5 navigation scenarios and they should only use it if they know wht they r doing with it. otherwise by default the wizard will provide the simpler NavigationService.

Doc added on #2246

Has the proposed doc been created as a stand-alone alternative to the current solution?
Or, has it been designed in a way that it could be used as a basis for future pages and features that will require handling scenarios that this document mentions?

The doc shows how to modify the project to reach more advanced navigation scenarios. The code from the docs could be used to do an advanced navigation feature that could be used as basis for other templates.

Was this page helpful?
0 / 5 - 0 ratings