3
votes

I refer from this StackOverflow question, regarding to MVVM Light:

I am trying to have a hamburger menu style navigation (see this sample). app by Microsoft on an example of how to do this) to:

1- have a convenient solution shared across all my pages. The sample mentioned above uses an AppShell Page as the root of the app instead of a Frame, that encapsulates the navigation menu and some behavior of the back button. That would be ideal.

2- Use the MVVM-Light navigation service to handle all the navigation from my view model conveniently.

Here is how the App.xml.Cs initializes the shell page onLaunched:

 protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        var shell = Window.Current.Content as AppShell;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (shell == null)
        {
            // Create a AppShell to act as the navigation context and navigate to the first page
            shell = new AppShell();

            // Set the default language
            shell.Language = ApplicationLanguages.Languages[0];

            shell.AppFrame.NavigationFailed += OnNavigationFailed;
        }

        // Place our app shell in the current Window
        Window.Current.Content = shell;

        if (shell.AppFrame.Content == null)
        {
            // When the navigation stack isn't restored, navigate to the first page
            // suppressing the initial entrance animation.
            var setup = new Setup(shell.AppFrame);
            setup.Initialize();

            var start = Mvx.Resolve<IMvxAppStart>();
            start.Start();
        }

        // Ensure the current window is active
        Window.Current.Activate();
    }

The thing is, as long as i navigate over the menu proviced by the AppShell everything works. But the ShowViewModel from MVVM Cross doesn't have any effect. I thought there shouldn't be any difference if pass the shell as Frame or the frame set on the AppShell. Does anyone have an idea what I can do about this or if there is an example with a working hamburger menu with MVVM cross?

The repository is open source on GitHub if you need an better overview or so.

https://github.com/Apply-Solutions/MoneyManager

I use MVVM Cross v4.0.0.0-beta1. Beta2 has currently another issue who prevents building in a UWP.

Thanks NPadrutt

2

2 Answers

0
votes

Not entirely sure what you are trying to do, but what you will probably need to navigate pages with a hamburger menu in a UWP app using MvvmCross as a framework, is a custom presenter, which handles the ShowViewModel method, and displays the associated view for the requested ViewModel in your hamburger container view.

0
votes

Okey this embarrassing. The issue was that the View for the ViewModel couldn't be resolved. And the reason for that was that I didn't replace the inheritance from page to views:MvxWindowsPage. With this, everything works with the default page presenter.

EDIT: in order to work with the navigation in the app shell, these pages need to be Pages. So you may either have to rewrite the navigation in the Appshell or may not adjust all Pages to MvxPage.