1
votes

I'm working with an UWP project that is using Prism to apply the MVVM pattern. I have a basic Frame like this:

<Frame   x:Name="SplitViewFrame" ></Frame>

With code behind, we can easily navigate this Frame:

SplitViewFrame.Navigate(typeof(MyPage),null);

But with MVVM we have to do it in ViewModel and I have no way to manage it. Does anyone know how to Navigate Frame in ViewModel with Prism?

1

1 Answers

1
votes

Prism's NavigationService has a reference to the frame to be able to do the navigation. This is injected during the application boot sequence. You can however create an app shell instead of the default single page navigation to support splitview/hamburger menu.

Have a look at the SplitView sample in the Windows Samples repository. During startup, the CreateShell method is overridden to support the splitview.

    protected override UIElement CreateShell(Frame rootFrame)
    {
        var shell = Container.Resolve<AppShell>();
        shell.SetContentFrame(rootFrame);
        return shell;
    }

Note that you currently can't combine default page navigation and a splitview on e.g. page 3 in a single Prism NavigationService.