Search code examples
c#mvvmwindows-runtimewin-universal-apptemplate10

Navigation within Page using Template10


I have problem how to implement sub-page navigation in UWP. The page is in RootFrame, which I can use on navigation. But i want to use something like this:

    <Page>
<Grid>
 <Frame x:Name="MyFrame"/>
</Grid>
</Page>

What I want is, use Navigate method of control MyFrame in ViewModel. I can call the method from code-behind, but I'm developing my app using MVVM. I'm not sure, if Template10 can work with sub-frames.

I appreciate any advice.

EDIT: More details: I have pivot control which is in page. the pivot has 2 tabs (pivotitems). The content of the pivotitem must be navigable. What I mean: I pivotitem 1, I need to have one Frame and use it for navigation in the pivotitem. My problem is, how to use or how to call the frame in pivotitem from ViewModel, especially I need to call Navigate method. Now I'm using Template10's navigation service and it's working with rootframe. I don't know, how to use it for other let's say sub-frames.


Solution

  • You can always do this.

    var nav = Bootstrapper.NavigationServiceFactory(BackButton.Attach, ExistingContent.Exclude, this.Frame);
    

    This will give you a navigation service for the frame in your page. You can then use session state, if you like.

    Bootstapper.SessionState["MyNav"] = nav;
    

    From here your view-model can access the service and navigate. You can repeat this for as many frames as you have. And you can then handle navigation in your view-model without consideration of "where" the frame is, just that your logic requires it to nav.

    Does this make sense?