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?
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?
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.