How to navigate between pages on windows phone 8.1 using mvvmcross?

1

I'm browsing between pages in Windows Phone 8.1 using the following call:

ShowViewModel<DetalheViewModel>();

When I click the back button the app closes. How do I implement the go back button functionality?

    
asked by anonymous 16.12.2014 / 22:44

1 answer

1

The ideal would be to create a class called BaseView (or something like that) that extends MvxWindowsPage and inherits its views from this BaseView, not from MvxWindowsPage.

Your BaseView class would look something like this:

public class BaseView : MvxWindowsPage
{
    public BaseView()
    {
        HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    }

    private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
    {
        if(Frame.CanGoBack)
        {
            e.Handled = true;
            Frame.GoBack();
        }
    }
}

You could also create a baseViewModel and put a command to it (GoBackCommand) and, instead of calling the Frame.GoBack (), call something like this:

var vm = ViewModel as MyBaseViewModel;
if (vm != null)
{
    e.Handled = true;
    vm.GoBackCommand.Execute(null);
}

Both forms are correct and work.

    
17.12.2014 / 15:02