How do I navigate between pages on windows phone 8.1 using mvvmcross?

Asked

Viewed 598 times

1

I’m browsing between pages on Windows Phone 8.1 using the following call:

ShowViewModel<DetalheViewModel>();

When I click the button come back the app closes. How do I implement the back button feature?

1 answer

1


The ideal would be to create a class called Baseview (or something like that) that extends to Mvxwindowspage and inherit your views from this Baseview, not 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 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.

  • Which in my Classlibrary is the reference for Hardwarebuttons ? I can’t add the reference to Windows.Phone.UI

  • No, that’s in your Windows Phone project. Views are specific, so they don’t enter the PCL.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.